[已解決]: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4
阿新 • • 發佈:2019-02-10
今天開發的時候,發現明明有這個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 去執行了。我也是醉了。