主机按钮点击后,Android应用程序崩溃

时间:2012-07-02 07:03:58

标签: android crash android-lifecycle

如果我按下主页按钮,我的应用程序崩溃了

后退按钮可以很好地进入仪表板,但是如果我按下它会崩溃:

  

07-02 16:50:51.834:E / AndroidRuntime(343):java.lang.RuntimeException:   无法暂停活动   {com.rt.paging / com.rt.paging.MKpagerActivity}:   显示java.lang.NullPointerException

这是我的代码

public class MKpagerActivity extends FragmentActivity {

    private PagerAdapter mPagerAdapter;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

      //initialsie the pager
            this.initialisePaging(); //crea un metodo! y lo implementa abajo!
    }

    /**
     * Initialise the fragments to be paged
     */
    private void initialisePaging() {

        List<Fragment> fragments = new Vector<Fragment>();
        fragments.add(Fragment.instantiate(this, Fragmen1.class.getName()));
        fragments.add(Fragment.instantiate(this, Fragmen2.class.getName()));
        this.mPagerAdapter  = new com.orchard.paging.PagerAdapter(super.getSupportFragmentManager(), fragments); //por que hay q decirle el paquete??


        //
        ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
        pager.setAdapter(this.mPagerAdapter);

    }


    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);
        // your stuff or nothing
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        // your stuff or nothing
    }



}

这是我的logCat

07-02 17:15:11.545: E/AndroidRuntime(327): FATAL EXCEPTION: main
07-02 17:15:11.545: E/AndroidRuntime(327): java.lang.RuntimeException: Unable to pause activity {com.orchard.paging/com.orchard.paging.MKpagerActivity}: java.lang.NullPointerException
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.access$1700(ActivityThread.java:117)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.os.Looper.loop(Looper.java:123)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-02 17:15:11.545: E/AndroidRuntime(327):  at java.lang.reflect.Method.invokeNative(Native Method)
07-02 17:15:11.545: E/AndroidRuntime(327):  at java.lang.reflect.Method.invoke(Method.java:507)
07-02 17:15:11.545: E/AndroidRuntime(327):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-02 17:15:11.545: E/AndroidRuntime(327):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-02 17:15:11.545: E/AndroidRuntime(327):  at dalvik.system.NativeStart.main(Native Method)
07-02 17:15:11.545: E/AndroidRuntime(327): Caused by: java.lang.NullPointerException
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
07-02 17:15:11.545: E/AndroidRuntime(327):  at com.orchard.paging.MKpagerActivity.onSaveInstanceState(MKpagerActivity.java:50)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.Activity.performSaveInstanceState(Activity.java:1037)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1181)
07-02 17:15:11.545: E/AndroidRuntime(327):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2336)
07-02 17:15:11.545: E/AndroidRuntime(327):  ... 12 more

那么,我错过了什么?为什么会崩溃?

如何读取代码中的哪一行?

谢谢!

1 个答案:

答案 0 :(得分:0)

问题出在JAR文件中,您需要对其进行更改,或者必须下载更新版本的jar文件

您可以查看this answer以了解更多信息。