startActivity运行时异常??怎么了?

时间:2011-09-12 10:14:45

标签: android exception

    09-12 13:11:49.400: ERROR/AndroidRuntime(3465): FATAL EXCEPTION: main
09-12 13:11:49.400: ERROR/AndroidRuntime(3465): java.lang.RuntimeException: Unable to pause activity {fy.aa.tablet/fy.aa.tablet.MainActivity}: java.lang.NullPointerException
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2490)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2447)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2425)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.access$1700(ActivityThread.java:122)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1012)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.os.Looper.loop(Looper.java:132)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.main(ActivityThread.java:4028)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at java.lang.reflect.Method.invoke(Method.java:491)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at dalvik.system.NativeStart.main(Native Method)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465): Caused by: java.lang.NullPointerException
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.View.dispatchSaveInstanceState(View.java:8258)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1990)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1996)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1996)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1996)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.View.saveHierarchyState(View.java:8241)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1603)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.Activity.onSaveInstanceState(Activity.java:1164)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.Activity.performSaveInstanceState(Activity.java:1114)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1184)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2472)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     ... 12 more

程序崩溃了:

  videolarGallery = (Gallery) findViewById(R.id.video_gallery);
           videolarGallery.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                try {
                    currVideo = (Video)videolarGallery.getAdapter().getItem(position);
                    Intent intent = new Intent();
                    intent.setClass(myAct, deneme.class);
                    startActivity(intent);
                } catch (Exception e) {
                    Logging.TraceMessage(e.getMessage(), Logging.ERROR, "videolarGallery.onItemClick()");
                }           
            }

           });

3 个答案:

答案 0 :(得分:3)

at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)

您没有为ViewPager分配适配器(或者没有以正确的方式分配)。调用ViewPager时,null的mAdapter成员变量为ViewPager.onSaveInstanceState()

请参阅ViewPager source第507行。

答案 1 :(得分:1)

你的例外中的

at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)
09-12 13:11:49.400: ERROR/AndroidRuntime(3465):     at android.view.View.dispatchSaveInstanceState(View.java:8258)

在ViewPager类的行号中。 507某人为空也请查看此View.java:8258

答案 2 :(得分:0)

这肯定是由于在Activity MainActivity中分配了一些空指针值。 如果您从此活动发布一些代码,那么更容易解决问题。