onAnimationEnd()导致应用程序关闭

时间:2011-03-06 14:00:58

标签: android

我目前正在关注一本名为Sams的书,在24小时内自学Android开发。

直到第7小时,这本书一直很顺利,这本书教导如何在转移到另一个屏幕之前听取动画结束(即飞溅到菜单)

以下是我的代码。帮帮我吧一直试图调试和logcat给了我一个03-06 13:56:57.045:错误/ AndroidRuntime(746):未捕获的处理程序:线程主要由于未捕获的异常退出。

QuizSplashActivity.Java

  package com.android.triviaquiz;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.Animation.AnimationListener;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class QuizSplashActivity extends QuizActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        startAnimation();
    }

    private void startAnimation() {
        // TODO Auto-generated method stub
        TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
        Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        logo1.startAnimation(fade1);

        TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
        Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
        logo2.startAnimation(fade2);
        fade2.setAnimationListener(new AnimationListener(){
            public void onAnimationEnd(Animation animation){
                startActivity(new Intent(QuizSplashActivity.this,QuizMenuActivity.class));
                QuizSplashActivity.this.finish();

            }


            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }


            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }




        });
        Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
        LayoutAnimationController controller = new LayoutAnimationController(spinin);
        TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
        for (int i = 0; i < table.getChildCount(); i++) {
            TableRow row = (TableRow) table.getChildAt(i);
            row.setLayoutAnimation(controller);
        }
    }

    @Override 
    protected void onPause() {
        super.onPause();
        //stop the animation
        TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
        logo1.clearAnimation();

        TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
        logo2.clearAnimation();

        TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
        for (int i = 0; 1< table.getChildCount(); i++){
            TableRow row = (TableRow) table.getChildAt(i);
            row.clearAnimation();
        }
    }   

}

Android Manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.triviaquiz"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/quizicon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".QuizSplashActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    <activity android:name="QuizMenuActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="7"/>

</manifest> 

完整LogCat

03-06 16:30:35.455: DEBUG/AndroidRuntime(775): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-06 16:30:35.465: DEBUG/AndroidRuntime(775): CheckJNI is ON
03-06 16:30:35.845: DEBUG/AndroidRuntime(775): --- registering native functions ---
03-06 16:30:36.405: DEBUG/ddm-heap(775): Got feature list request
03-06 16:30:37.116: DEBUG/AndroidRuntime(775): Shutting down VM
03-06 16:30:37.126: DEBUG/dalvikvm(775): DestroyJavaVM waiting for non-daemon threads to exit
03-06 16:30:37.126: DEBUG/dalvikvm(775): DestroyJavaVM shutting VM down
03-06 16:30:37.136: DEBUG/dalvikvm(775): HeapWorker thread shutting down
03-06 16:30:37.136: DEBUG/dalvikvm(775): HeapWorker thread has shut down
03-06 16:30:37.146: ERROR/AndroidRuntime(775): ERROR: thread attach failed
03-06 16:30:37.146: DEBUG/jdwp(775): JDWP shutting down net...
03-06 16:30:37.166: INFO/dalvikvm(775): Debugger has detached; object registry had 1 entries
03-06 16:30:37.166: DEBUG/dalvikvm(775): VM cleaning up
03-06 16:30:37.215: DEBUG/dalvikvm(775): LinearAlloc 0x0 used 628628 of 5242880 (11%)
03-06 16:30:37.815: DEBUG/AndroidRuntime(783): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-06 16:30:37.815: DEBUG/AndroidRuntime(783): CheckJNI is ON
03-06 16:30:38.146: DEBUG/AndroidRuntime(783): --- registering native functions ---
03-06 16:30:38.825: DEBUG/ddm-heap(783): Got feature list request
03-06 16:30:39.575: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.triviaquiz/.QuizSplashActivity }
03-06 16:30:39.655: DEBUG/AndroidRuntime(783): Shutting down VM
03-06 16:30:39.665: DEBUG/dalvikvm(783): DestroyJavaVM waiting for non-daemon threads to exit
03-06 16:30:39.685: DEBUG/dalvikvm(783): DestroyJavaVM shutting VM down
03-06 16:30:39.685: DEBUG/dalvikvm(783): HeapWorker thread shutting down
03-06 16:30:39.705: DEBUG/dalvikvm(783): HeapWorker thread has shut down
03-06 16:30:39.725: DEBUG/jdwp(783): JDWP shutting down net...
03-06 16:30:39.735: INFO/dalvikvm(783): Debugger has detached; object registry had 1 entries
03-06 16:30:39.745: DEBUG/dalvikvm(783): VM cleaning up
03-06 16:30:39.795: ERROR/AndroidRuntime(783): ERROR: thread attach failed
03-06 16:30:39.865: DEBUG/dalvikvm(783): LinearAlloc 0x0 used 638596 of 5242880 (12%)
03-06 16:30:39.915: INFO/ActivityManager(59): Start proc com.android.triviaquiz for activity com.android.triviaquiz/.QuizSplashActivity: pid=790 uid=10027 gids={}
03-06 16:30:40.196: DEBUG/ddm-heap(790): Got feature list request
03-06 16:30:41.455: INFO/ActivityManager(59): Displayed activity com.android.triviaquiz/.QuizSplashActivity: 1799 ms (total 30322 ms)
03-06 16:30:46.295: INFO/ActivityManager(59): Starting activity: Intent { cmp=com.android.triviaquiz/.QuizMenuActivity }
03-06 16:30:46.365: DEBUG/AndroidRuntime(790): Shutting down VM
03-06 16:30:46.365: WARN/dalvikvm(790): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-06 16:30:46.375: ERROR/AndroidRuntime(790): Uncaught handler: thread main exiting due to uncaught exception
03-06 16:30:46.435: ERROR/AndroidRuntime(790): java.lang.RuntimeException: Unable to pause activity {com.android.triviaquiz/com.android.triviaquiz.QuizSplashActivity}: java.lang.NullPointerException
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3162)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3119)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3102)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.access$2400(ActivityThread.java:119)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.os.Looper.loop(Looper.java:123)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at java.lang.reflect.Method.invoke(Method.java:521)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at dalvik.system.NativeStart.main(Native Method)
03-06 16:30:46.435: ERROR/AndroidRuntime(790): Caused by: java.lang.NullPointerException
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at com.android.triviaquiz.QuizSplashActivity.onPause(QuizSplashActivity.java:77)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.Activity.performPause(Activity.java:3782)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1190)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3149)
03-06 16:30:46.435: ERROR/AndroidRuntime(790):     ... 12 more
03-06 16:30:46.485: INFO/Process(59): Sending signal. PID: 790 SIG: 3
03-06 16:30:46.485: INFO/dalvikvm(790): threadid=7: reacting to signal 3
03-06 16:30:46.565: INFO/dalvikvm(790): Wrote stack trace to '/data/anr/traces.txt'
03-06 16:30:46.825: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{43db5470 com.android.triviaquiz/.QuizSplashActivity}
03-06 16:30:49.645: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
03-06 16:30:50.340: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{43db5470 com.android.triviaquiz/.QuizSplashActivity}
03-06 16:30:56.847: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{43dd6cf8 com.android.triviaquiz/.QuizMenuActivity}
03-06 16:31:00.245: DEBUG/dalvikvm(59): GC freed 17596 objects / 838928 bytes in 183ms
03-06 16:31:00.355: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{43db5470 com.android.triviaquiz/.QuizSplashActivity}

2 个答案:

答案 0 :(得分:0)

您确定布局代码中是否存在TableLayout01,TextViewTopTitle和TextViewBottomTitle?

答案 1 :(得分:0)

我认为这(在您的OnPause处理程序中)可能是您的问题:

for (int i = 0; 1< table.getChildCount(); i++){

应该是:

for (int i = 0; i < table.getChildCount(); i++){

注意for循环的第二部分 - 你使用“1&lt; table.getChildCount()”而不是“i&lt; table.getChildCount()”。