You are lucky that that code compiles! (Or more precise, quite the unlucky one...)
The problem is with your code. First of all you should learn some Java, otherwise you will be stuck. Basic Concepts like classes, methods, interfaces, objects, code blocks and syntax. As for the issue above: import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class inputTest extends Activity { private Handler mHandler = new Handler(); private TextView timer; public long mStartTime; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // This creates the buttons Button buttonStart = (Button) findViewById(R.id.button_start); // These will fail if executed before setContentView Button buttonStop = (Button) findViewById(R.id.button_stop); timer = (TextView)findViewById(R.id.timer); buttonStart.setOnClickListener(mStartListener); buttonStop.setOnClickListener(mStopListener); } // This is the end of onCreate() // These are executed well before onCreate (These are called anonymous inner classes in Java) OnClickListener mStartListener = new OnClickListener () { public void onClick (View v) { if (mStartTime == 0L){ mStartTime = System.currentTimeMillis(); mHandler.removeCallbacks(mUpdateTimeTask); mHandler.postDelayed(mUpdateTimeTask, 100); } } }; OnClickListener mStopListener = new OnClickListener() { public void onClick(View v) { mHandler.removeCallbacks(mUpdateTimeTask); } }; private Runnable mUpdateTimeTask = new Runnable() { public void run() { final long start = mStartTime; long millis = SystemClock.uptimeMillis() - start; int seconds = (int) (millis / 1000); int minutes = seconds / 60; seconds = seconds % 60; if (seconds < 10) { timer.setText("" + minutes + ":0" + seconds); } else { timer.setText("" + minutes + ":" + seconds); } mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); } }; } On 21 янв, 21:37, Matt <mkabro...@gmail.com> wrote: > Hello, > > Im new to android dev, and am getting a force close on my first > application and I cant figure it out for the life of me. Hope someone > can spot it! > > import android.app.Activity; > import android.os.Bundle; > import android.os.Handler; > import android.os.SystemClock; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.TextView; > > public class inputTest extends Activity { > > private Handler mHandler = new Handler(); > public long mStartTime; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > setContentView(R.layout.main); > > buttonStart.setOnClickListener(mStartListener); > buttonStop.setOnClickListener(mStopListener); > > } > > Button buttonStart = (Button) findViewById(R.id.button_start); > Button buttonStop = (Button) findViewById(R.id.button_stop); > TextView timer = (TextView)findViewById(R.id.timer); > > OnClickListener mStartListener = new OnClickListener () { > public void onClick (View v) { > if (mStartTime == 0L){ > mStartTime = System.currentTimeMillis(); > mHandler.removeCallbacks(mUpdateTimeTask); > mHandler.postDelayed(mUpdateTimeTask, 100); > } > } > }; > > OnClickListener mStopListener = new OnClickListener() { > public void onClick(View v) { > mHandler.removeCallbacks(mUpdateTimeTask); > } > }; > > private Runnable mUpdateTimeTask = new Runnable() { > public void run() { > final long start = mStartTime; > long millis = SystemClock.uptimeMillis() - start; > int seconds = (int) (millis / 1000); > int minutes = seconds / 60; > seconds = seconds % 60; > > if (seconds < 10) { > timer.setText("" + minutes + ":0" + seconds); > } else { > timer.setText("" + minutes + ":" + > seconds); > } > > mHandler.postAtTime(this, > start + (((minutes * 60) + seconds + 1) * 1000)); > } > }; > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en