3 Replies - 625 Views - Last Post: 30 September 2012 - 12:50 PM

#1 Jake1208  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 12

This app force closes everytime I press a button other then start/stop

Posted 29 September 2012 - 05:44 PM

Hi I'm trying to make a Scoreboard app in Android but when I test it every time I hit the addhome, addaway, subhome and subaway buttons it force closes. I checked the code but there are no errors. The app does not force close when I press start or stop but it does nothing.

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class MainActivity extends Activity {
	
	int homecount, awaycount, minutes, seconds;
	TextView home, away;
	Button stop, start, reset, addhome, subhome, addaway, subaway;
	TextView time;
	private boolean running = false;
	private long startTime = 0;
	private long stopTime = 0;
	private long elapsed = 0;
    int X = 1;
	public void updateDisplay() {
		
		time.setText(minutes + ":" + seconds);
	}


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		time = (TextView) findViewById(R.id.timer);
		start = (Button) findViewById(R.id.bStart);
		stop = (Button) findViewById(R.id.bStop);
		reset = (Button) findViewById(R.id.bReset);
		addhome = (Button) findViewById(R.id.bAddHome);
		addaway = (Button) findViewById(R.id.bAddAway);
		subhome = (Button) findViewById(R.id.bSubHome);
		subaway = (Button) findViewById(R.id.bSubAway);
		home = (TextView) findViewById(R.id.home);
		away = (TextView) findViewById(R.id.away);

		addhome.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				homecount++;
				home.setText(homecount);
			}
		});

		subhome.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				homecount--;
				home.setText(homecount);
			}
		});
		addaway.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				awaycount++;
				away.setText(awaycount);
			}
		});

		subhome.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				awaycount--;
				away.setText(awaycount);
			}
		});

		start.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				start();

			}

		});
	
	stop.setonclickListener(new View.onclickListener() {

		public void onclick(View v) {

			stop();

		}

	});
	reset.setonclickListener(new View.onclickListener() {

		public void onclick(View v) {

			reset();

		}

	});
	
}
	public void start() {
		this.startTime = System.nanoTime();
		this.running = true;
		
	}

	public void stop() {
		this.stopTime = System.nanoTime();
		this.running = false;
		
	}

	public void reset() {
		this.startTime = 0;
		this.stopTime = 0;
		this.running = false;
	}

	

	
	public long getElapsedTimeSeconds() {
		if (running) {
			elapsed = ((System.nanoTime() - startTime) / 1000000);
		} else {
			elapsed = ((stopTime - startTime) / 1000000);
		}
		
		int seconds = (int) (elapsed/ 1000) % 60 ;
		int minutes = (int) ((elapsed / (1000*60)) % 60);
		do {
            updateDisplay();
            
        } while (X > 1);
		
		
		
		
		return elapsed;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case R.id.newgame:

		}
		return true;
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: This app force closes everytime I press a button other then start/stop

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10560
  • View blog
  • Posts: 39,070
  • Joined: 27-December 08

Re: This app force closes everytime I press a button other then start/stop

Posted 29 September 2012 - 10:13 PM

Moved to Android.

Are you sure the Logcat doesn't show any errors?
Was This Post Helpful? 1
  • +
  • -

#3 Jake1208  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 12

Re: This app force closes everytime I press a button other then start/stop

Posted 30 September 2012 - 10:03 AM

here is my logcat
  09-30 16:55:17.811: W/ResourceType(644): No package identifier when getting value for resource number 0x00000001
	09-30 16:55:17.811: D/AndroidRuntime(644): Shutting down VM
	09-30 16:55:17.841: W/dalvikvm(644): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
	09-30 16:55:17.881: E/AndroidRuntime(644): FATAL EXCEPTION: main
	09-30 16:55:17.881: E/AndroidRuntime(644): android.content.res.Resources$NotFoundException: String resource ID #0x1
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.content.res.Resources.getText(Resources.java:201)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.widget.TextView.setText(TextView.java:2817)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at jakes.apps.scoreboard.MainActivity$3.onclick(MainActivity.java:65)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.view.View.performClick(View.java:2408)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.view.View$PerformClick.run(View.java:8816)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.os.Handler.handleCallback(Handler.java:587)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.os.Handler.dispatchMessage(Handler.java:92)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.os.Looper.loop(Looper.java:123)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at java.lang.reflect.Method.invokeNative(Native Method)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at java.lang.reflect.Method.invoke(Method.java:521)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
	09-30 16:55:17.881: E/AndroidRuntime(644): 	at dalvik.system.NativeStart.main(Native Method)
	09-30 16:55:20.241: I/Process(644): Sending signal. PID: 644 SIG: 9


Was This Post Helpful? 0
  • +
  • -

#4 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: This app force closes everytime I press a button other then start/stop

Posted 30 September 2012 - 12:50 PM

Your problem is you are passing an int to your <textview>.setText(...) where you should be passing a String.
For your home.setText do the following:
home.setText(homecount+"");



and for your away.setText do the following:
away.setText(awaycount+"");


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1