Frage

i have a countDownTimer , and it fisish the time i want to go to an error screen this is the code for countDownTimer

timer = new CountDownTimer(36000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                // TODOAuto-generated method stub
                remaingTimer.setText(millisUntilFinished + "");
            }

            @Override
            public void onFinish() {
                // TODO Auto-generated methodstub
                Intent goToMainTabs = new Intent(
                        "com.localizedbasedcompetition.FINISHTIME");
                startActivity(goToMainTabs);
            }
        };

i want to go to finishtime activity , and this is the code for finishtime activity

public class FinishTime extends Activity implements OnClickListener{
    Button backToMain;
    TextView errorMessage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.finishtime);
        initialize();
    }
    private void initialize() {
        // TODO Auto-generated method stub
        backToMain= (Button)findViewById(R.id.bFinishTimeBackToMain);
        errorMessage=(Button)findViewById(R.id.tvFinishTime);
        backToMain.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bFinishTimeBackToMain:
            Intent goToMainTabs = new Intent(
                    "com.localizedbasedcompetition.MAINTABS");
            startActivity(goToMainTabs);
            break;

        default:
            break;
        }
    }

}

and this is the mainfest for finishtime activity

<activity
            android:name=".FinishTime"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.localizedbasedcompetition.FINISHTIME" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

my problem is when the countDownTimer finish counting , i got an excpetion , what am i doing wrong?

This is the exception

06-23 14:16:14.352: E/AndroidRuntime(1001): FATAL EXCEPTION: main
06-23 14:16:14.352: E/AndroidRuntime(1001): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.localizedbasedcompetition/com.localizedbasedcompetition.FinishTime}: java.lang.ClassCastException: android.widget.TextView
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.os.Looper.loop(Looper.java:123)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at java.lang.reflect.Method.invokeNative(Native Method)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at java.lang.reflect.Method.invoke(Method.java:521)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at dalvik.system.NativeStart.main(Native Method)
06-23 14:16:14.352: E/AndroidRuntime(1001): Caused by: java.lang.ClassCastException: android.widget.TextView
06-23 14:16:14.352: E/AndroidRuntime(1001):     at com.localizedbasedcompetition.FinishTime.initialize(FinishTime.java:24)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at com.localizedbasedcompetition.FinishTime.onCreate(FinishTime.java:19)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-23 14:16:14.352: E/AndroidRuntime(1001):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-23 14:16:14.352: E/AndroidRuntime(1001):     ... 11 more
War es hilfreich?

Lösung

You need to call start() on the CountDownTimer. Otherwise it's not doing anything.

http://developer.android.com/reference/android/os/CountDownTimer.html

and according to your exception you have defined something as a TextView in your XML that you are accidentally casting to something else (is that your Button cast?) impossible to tell without seeing the xml, but that's what the exception is. Make sure you refer to your Views correctly in the Java as you've defined them in the XML.

oh, and as iNan points out, clean your project just in case after you've fixed. Eclipse has a nasty way of not updating things like this from time to time.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top