Android主要活动不断抛出空指针异常

时间:2018-10-31 07:37:10

标签: java android

我正在尝试运行我的主要活动,但是每次我的飞溅活动结束时,我都会不断得到Java NullPointerException。我正在用黄油刀绑定我的变量。

这是我的主要活动代码:

private SectionsPagerAdapter mSectionsPagerAdapter;
@BindView(R.id.container) ViewPager mViewPager;
@BindView(R.id.tabs) TabLayout mTabLayout;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    doBindService();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mTabLayout.setupWithViewPager(mViewPager);


}

这是我的错误报告:

java.lang.RuntimeException: Unable to start activity ComponentInfo{yobra.msupa.brianyobra.scenatra/yobra.msupa.brianyobra.kilo.MainActivty}: java.lang.NullPointerException
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
                  at android.app.ActivityThread.access$600(ActivityThread.java:141)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:5103)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:525)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: java.lang.NullPointerException
                  at yobra.msupa.brianyobra.kilo.MainActivty.onCreate(MainActivty.java:69)
                  at android.app.Activity.performCreate(Activity.java:5133)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:5103) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:525) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                  at dalvik.system.NativeStart.main(Native Method) 

0 个答案:

没有答案