2014-01-09 50 views
4

我得到一個問題,我的XML文件是遵循java.lang.reflect.invocationtargetexception android系統

<ImageView 
    android:id="@+id/edt_order" 
    android:layout_width="50dp" 
    android:layout_height="match_parent" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/separator_bottom" 
    android:background="#fff" 
    android:clickable="true" 
    android:onClick="clickHandler" 
    android:src="@drawable/edit_button" /> 

<ImageView 
    android:id="@+id/save_change_order_id" 
    android:layout_width="100dp" 
    android:layout_height="match_parent" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/separator_bottom" 
    android:background="#fff" 
    android:clickable="true" 
    android:visibility="gone" 
    android:onClick="clickHandler" 
    android:src="@drawable/save_button" /> 

其實這是XML定義定製警報的對話的一部分。我想,當我點擊第一ImageView(android:id="@+id/edt_order"),那麼它的知名度成爲Invisible和地方的這種ImageView調用setVisible一個又一個ImageView(android:id="@+id/save_change_order_id")

爲此,我寫下下面的代碼中的java文件:

public void clickHandler(View v) { 

    if (v.getId() == R.id.edt_order) {         
     System.out.println(" edit buton click");      
     System.out.println("Click my Order"); 
     img_v_save_change_order_var.setVisibility(ImageView.VISIBLE); 
     img_btn_edit_order_var.setVisibility(ImageView.INVISIBLE); 
     int jcount = 0; 
     // save_change_order_id 
     jcount = countjournals();    
     System.out.println("jcount = " + jcount);    

     if (jcount < 1) {    
      alertShow(); 
     } else { 
      intiliazeOrderListDialog();       
     } 
    }    
} 

但我得到一個例外如下:

01-09 06:12:14.550: D/AndroidRuntime(1981): Shutting down VM 
01-09 06:12:14.550: W/dalvikvm(1981): threadid=1: thread exiting with uncaught exception (group=0xb3ab3b90) 
01-09 06:12:14.730: E/AndroidRuntime(1981): FATAL EXCEPTION: main 
01-09 06:12:14.730: E/AndroidRuntime(1981): Process: com.example.demoekot, PID: 1981 
01-09 06:12:14.730: E/AndroidRuntime(1981): java.lang.IllegalStateException: Could not execute method of the activity 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.view.View$1.onClick(View.java:3814) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.view.View.performClick(View.java:4424) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.view.View$PerformClick.run(View.java:18383) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.os.Handler.handleCallback(Handler.java:733) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.os.Handler.dispatchMessage(Handler.java:95) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.os.Looper.loop(Looper.java:137) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.app.ActivityThread.main(ActivityThread.java:4998) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at java.lang.reflect.Method.invokeNative(Native Method) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at java.lang.reflect.Method.invoke(Method.java:515) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at dalvik.system.NativeStart.main(Native Method) 
01-09 06:12:14.730: E/AndroidRuntime(1981): Caused by: java.lang.reflect.InvocationTargetException 
01-09 06:12:14.730: E/AndroidRuntime(1981): at java.lang.reflect.Method.invokeNative(Native Method) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at java.lang.reflect.Method.invoke(Method.java:515) 
01-09 06:12:14.730: E/AndroidRuntime(1981): at android.view.View$1.onClick(View.java:3809) 
01-09 06:12:14.730: E/AndroidRuntime(1981): ... 11 more 
01-09 06:12:14.730: E/AndroidRuntime(1981): Caused by: java.lang.NullPointerException 
01-09 06:12:14.730: E/AndroidRuntime(1981): at com.example.demoekot.MainScreen.clickHandler(MainScreen.java:428) 
01-09 06:12:14.730: E/AndroidRuntime(1981): ... 14 more 

爲什麼我得到這個異常?

+0

什麼是line 428'MainaScreen.java'? – Raghunandan

+0

「引起的:java.lang.NullPointerException在com.example.demoekot.MainScreen.clickHandler(MainScreen.java:428)」 - 有一些'null'在行428取消引用。 – laalto

+0

我的第428行是: - img_v_save_change_order_var。 setVisibility(ImageView.VISIBLE); –

回答

1

我認爲這是在你的主類圖像的聲明的問題。