//this is the resource which i want to access by setContentView method.
我正在使用平板电脑的横向模式,此资源文件位于lyaout-sw720dp-land文件夹
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//for landscape screen
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.prof_res_recycler_view_tab);
...
02-22 18:47:43.129: E/AndroidRuntime(5167): FATAL EXCEPTION: main
02-22 18:47:43.129: E/AndroidRuntime(5167): Process: com.pg.dentistpartnerapp.mt, PID: 5167
02-22 18:47:43.129: E/AndroidRuntime(5167): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pg.dentistpartnerapp.mt/com.pg.dentistpartnerapp.mt.activities.SearchagainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.ImageButton.getVisibility()' on a null object reference
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.os.Handler.dispatchMessage(Handler.java:102)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.os.Looper.loop(Looper.java:135)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread.main(ActivityThread.java:5221)
02-22 18:47:43.129: E/AndroidRuntime(5167): at java.lang.reflect.Method.invoke(Native Method)
02-22 18:47:43.129: E/AndroidRuntime(5167): at java.lang.reflect.Method.invoke(Method.java:372)
02-22 18:47:43.129: E/AndroidRuntime(5167): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-22 18:47:43.129: E/AndroidRuntime(5167): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-22 18:47:43.129: E/AndroidRuntime(5167): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.ImageButton.getVisibility()' on a null object reference
02-22 18:47:43.129: E/AndroidRuntime(5167): at com.pg.dentistpartnerapp.mt.activities.SearchagainActivity.openSearchBox(SearchagainActivity.java:279)
02-22 18:47:43.129: E/AndroidRuntime(5167): at com.pg.dentistpartnerapp.mt.activities.SearchagainActivity.onCreate(SearchagainActivity.java:239)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.Activity.performCreate(Activity.java:5933)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-22 18:47:43.129: E/AndroidRuntime(5167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
02-22 18:47:43.129: E/AndroidRuntime(5167): ... 10 more
答案 0 :(得分:2)
您的错误在第279行(在方法openSearchBox(...)
中),而不在您显示的代码中。看起来您正在尝试调用getVisibility()
和ImageButton
引用尚未设置为任何内容(null)。
Caused by: java.lang.NullPointerException:
Attempt to invoke virtual method 'int android.widget.ImageButton.getVisibility()' on a null object reference
at com.pg.dentistpartnerapp.mt.activities.SearchagainActivity.openSearchBox(SearchagainActivity.java:279)