今天开发的时候,发现明明有这个id,而且也通过findviewbyid获取了,但是为什么最后得到viewpager 是空呢?
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
at com.wbm.app.pda.LoginActivity.initMainFragment(LoginActivity.java:152)at com.wbm.app.pda.LoginActivity.init(LoginActivity.java:88)
at com.wbm.app.pda.LoginActivity.onCreate(LoginActivity.java:56)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
最后发现:真的让人哭笑不得
我应该在MainActivity 里面去执行的,反而在LoginActivity 去执行了。我也是醉了。