2016-02-22 137 views
-3
//this is the resource which i want to access by setContentView method. 

我使用橫向模式的平板電腦和這個資源文件是lyaout-sw720dp土地文件夾

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

請提供onCreate()方法 –

+0

這是一個NullPointerException異常的全身...'02-22 18:47:43.129:E/AndroidRuntime(5167):了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.pg.dentistpartnerapp.mt.activities.SearchagainActivity}:java.lang.NullPointerException:嘗試在空對象引用上調用虛擬方法'int android.widget.ImageButton.getVisibility()' ' – Shark

+0

把你的xml代碼 –

回答

2

您的錯誤位於第279行(在方法openSearchBox(...)中),而不是您顯示的代碼中。它看起來像你試圖撥打getVisibility() on和ImageButton引用尚未設置爲任何東西(空)。

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) 
相關問題