Adrian Schäfer
- Forum-Beiträge: 5
16.05.2011, 14:15:02 via Website
16.05.2011 14:15:02 via Website
Servus zusammen,
ich versuche gerade für meine Tabu-App einen Countdown zu erstellen. Ich hab mich an diesem Tutorial orientiert: http://dewful.com/?p=3
leider bekomme ich eine Nullpoint Exception wenn ich versuche bei meinem Label .setText(..) aufzurufen. hier mein Code:
Ich bin noch nicht lange beim Programmieren dabei, also verzeiht mir bitte falls der Fehler etwas, naja... dumm ist ^^
ich versuche gerade für meine Tabu-App einen Countdown zu erstellen. Ich hab mich an diesem Tutorial orientiert: http://dewful.com/?p=3
leider bekomme ich eine Nullpoint Exception wenn ich versuche bei meinem Label .setText(..) aufzurufen. hier mein Code:
1package de.test;
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.os.CountDownTimer;
6import android.widget.SeekBar;
7import android.widget.TextView;
8
9public class test extends Activity {
10 SeekBar timer;
11 TextView tv;
12
13 /** Called when the activity is first created. */
14 @Override
15 public void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 timer = (SeekBar) findViewById(R.id.seekBar);
18 tv = (TextView) findViewById(R.id.tv);
19 this.setContentView(R.layout.main);
20 // 5000 is the starting number (in milliseconds)
21 // 1000 is the number to count down each time (in milliseconds)
22 MyCount counter = new MyCount(5000, 1000);
23 counter.start();
24 }
25
26 // countdowntimer is an abstract class, so extend it and fill in methods
27 public class MyCount extends CountDownTimer {
28 public MyCount(long millisInFuture, long countDownInterval) {
29 super(millisInFuture, countDownInterval);
30 }
31
32 @Override
33 public void onFinish() {
34 tv.setText("finsish");
35 }
36
37 @Override
38 public void onTick(long millisUntilFinished) {
39 String b = String.valueOf(millisUntilFinished);
40 tv.setText(b);
41// int a = (int) millisUntilFinished;
42// timer.setProgress(a);
43 }
44 }
45}
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.os.CountDownTimer;
6import android.widget.SeekBar;
7import android.widget.TextView;
8
9public class test extends Activity {
10 SeekBar timer;
11 TextView tv;
12
13 /** Called when the activity is first created. */
14 @Override
15 public void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 timer = (SeekBar) findViewById(R.id.seekBar);
18 tv = (TextView) findViewById(R.id.tv);
19 this.setContentView(R.layout.main);
20 // 5000 is the starting number (in milliseconds)
21 // 1000 is the number to count down each time (in milliseconds)
22 MyCount counter = new MyCount(5000, 1000);
23 counter.start();
24 }
25
26 // countdowntimer is an abstract class, so extend it and fill in methods
27 public class MyCount extends CountDownTimer {
28 public MyCount(long millisInFuture, long countDownInterval) {
29 super(millisInFuture, countDownInterval);
30 }
31
32 @Override
33 public void onFinish() {
34 tv.setText("finsish");
35 }
36
37 @Override
38 public void onTick(long millisUntilFinished) {
39 String b = String.valueOf(millisUntilFinished);
40 tv.setText(b);
41// int a = (int) millisUntilFinished;
42// timer.setProgress(a);
43 }
44 }
45}
Ich bin noch nicht lange beim Programmieren dabei, also verzeiht mir bitte falls der Fehler etwas, naja... dumm ist ^^
— geändert am 16.05.2011, 14:16:06
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.