Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 16th, 2010, 05:55 AM   #1 (permalink)
New Member
 
Join Date: Oct 2009
Posts: 13
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default mUpdateTimeTask UI help

I'm trying to create a basic sample Stop Watch type application which basically displays a timer. It can then be stopped and started. I'm using the mUpdateTimeTask to do this. However my app just crashed when I run it. Below is the code; can anyone help?


public
class TimeWatch extends Activity {
/** Called when the activity is first created. */
private Button btnStart;
private Button btnStop;


private TextView mTimeLabel;

privatelongmStartTime;

final Handler mHandler = new Handler();


private
Runnable mUpdateTimeTask = new Runnable()
{
publicvoid run()
{
finallong start = mStartTime;

long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;

if (seconds < 10) {
time.setText("" + minutes + ":0" + seconds);
}
else {
time.setText("" + minutes + ":" + seconds);
}
mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000));
mHandler.postDelayed(mUpdateTimeTask, 100);
}};

private OnClickListener mClickListener = new OnClickListener() {

publicvoid onClick(View v) {
if (v.getId() == R.id.btnCalculate) {
if (mStartTime == 0L) {
mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
}
else{
mHandler.removeCallbacks(mUpdateTimeTask);
}
}
}};




publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Access the various widgets by their id in R.java
time= (TextView) findViewById(R.id.time);
btnStart.setOnClickListener(mClickListener);
btnStop.setOnClickListener(mClickListener);

}

}


wertyu is offline  
Last edited by wertyu; January 16th, 2010 at 06:05 AM.
Reply With Quote
Sponsors
Old January 16th, 2010, 06:03 AM   #2 (permalink)
New Member
 
Join Date: Oct 2009
Posts: 13
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ActivityThread.performLaunchActivity(ActivityThrea d$ActivityRecord, Intent) line: 2454
ActivityThread.handleLaunchActivity(ActivityThread $ActivityRecord, Intent) line: 2470
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119
ActivityThread$H.handleMessage(Message) line: 1821
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4310
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
wertyu is offline  
Reply With Quote
Old January 16th, 2010, 11:25 AM   #3 (permalink)
Member
 
Join Date: Nov 2009
Posts: 103
 
Device(s): Droid
Thanks: 0
Thanked 4 Times in 4 Posts
Default

#1, don't recreate the wheel > android.widget.Chronometer. It may not be exactly what you want ... but its self contained.

#2, Your missing quite a bit from your onCreate() method.
#2.1, Your not setting the content view. Which means no layout has been inflated. All R.layout.xxx will return null
#2.2, Both button references are never initialized so they are both null as well.

#3, the stack trace you posted from the exception, seems incomplete.
KeithG is offline  
Reply With Quote
Old January 29th, 2010, 06:40 AM   #4 (permalink)
New Member
 
Join Date: Oct 2009
Posts: 13
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Keith that's just what I wanted....I'm new to this
wertyu is offline  
Reply With Quote
Old February 6th, 2012, 11:39 AM   #5 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey wertyu i want the executed code for this problem. can u post it here plz, it would be very helpful to me..how that btncalclate and time are are present in Resource file..
rajkumarcs545 is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:42 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo