0

如果我按下主页按钮,我有一个应用程序会崩溃,

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

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

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

如何阅读违规代码的哪一行?

谢谢!

4

1 回答 1

0

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

您可以查看此答案以了解更多信息。

于 2012-07-02T07:27:24.583 回答