Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Help with my code?

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    My Mood
    Cynical
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with my code?

    Hi guys,
    This is my first post of many, I need help. Whenever I try to compile the first program I've ever written for android the program I've made crashes instantly on the emulator and I get the "Force close option".

    I'm really stuck, how do I fix this error? I'm pretty certain it's nothing to do with my code but I'll post my code here anyways.

    If anyone could help me over TeamViewer, that would be brilliant.

    [spoiler]
    Java:
    package bradley.flay.is.a.baws;
     
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
     
    public class BradleysprojectActivity extends Activity {
     
    	//Global Variables
    	int counter = 0;
    	Button button1 = (Button) findViewById(R.id.bAdd);;
    	Button button2 = (Button) findViewById(R.id.bSub);
    	TextView textview1 = (TextView) findViewById(R.id.tvTheNumIsOne);
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            button1.setOnClickListener(new View.OnClickListener(){
    			public void onClick(View v) {
    				counter++;
    				textview1.setText("The total is " + counter);
    			};
    			});
     
            button2.setOnClickListener(new View.OnClickListener() {
    			public void onClick(View v) {
    				counter--;
    				textview1.setText("The total is " + counter);
    			}
    		});
     
     
    }
     
    }
    [/spoiler]

    [spoiler]
    XML
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
     
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="The total is 0" 
            android:id="@+id/tvTheNumIsOne"
            android:textSize="30dp"
            android:gravity="center"
            />
     
    	<Button
    	    android:layout_width="200dp"
    	    android:layout_height="45dp"
    	    android:text="Add one"
    	    android:id="@+id/bAdd"
     
    	    />
     
    	<Button
    	    android:layout_width="200dp"
    	    android:layout_height="45dp" 
    	    android:text="Subtract one"
    	    android:id="@+id/bSub"
    	    android:gravity="center"
    	    />
     
    </LinearLayout>
    [/spoiler]

    EDIT: Just realised I have this error when trying to debug on the SDK:
    Error:
    Can't bind to local 8615 for debugger

    Hope you can help me with this,
    Ralbeyd
    Last edited by Ralbeyd; January 30th, 2012 at 05:59 PM. Reason: Noticed an error


Similar Threads

  1. Help merging program code with GUI code
    By Wilha in forum AWT / Java Swing
    Replies: 2
    Last Post: January 25th, 2012, 07:03 PM
  2. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  3. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  4. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM