我得到這個例外,但是說明沒有幫助我的人:IllegalStateException異常上的一個按鈕
07-01 12:31:09.723: E/AndroidRuntime(12530): java.lang.IllegalStateException: Could not execute method of the activity
功能,拋出它(因爲當我點擊特定的按鈕它發生的代碼)是:
public void go(View view){
String ghici = litera.getText().toString();
cuvAfisat = cuvant.getText().toString();
litera.setText("");
if(ghici!="")
if(cuvAles.contains(ghici)){
for (int poz = 0; poz < cuvAles.length(); poz ++) {
cuvAfisat = cuvant.getText().toString();
if (cuvAles.charAt(poz) == ghici.charAt(0)) {
System.out.println(poz);
cuvAfisat = cuvAfisat.substring(0, poz*2-1)+ ghici+ cuvAfisat.substring(poz*2+1, cuvAfisat.length());
System.out.println(cuvAfisat);
cuvant.setText(cuvAfisat);
}
}
}
else {
gresite.append(ghici+" ");
valIncercari--;
incercari.setText(valIncercari+"");
if(valIncercari == 0){
Toast.makeText(this, "Ai pierdut :(", Toast.LENGTH_LONG).show();
litera.setEnabled(false);
go.setEnabled(false);
char[] stringArray = cuvAles.toCharArray();
StringBuilder sb = new StringBuilder();
for(int index=0; index < stringArray.length; index++) {
sb.append(stringArray[index]);
sb.append(" ");
}
cuvant.setText(sb);
}
}
}
的事情是,它並沒有這樣做,當此行被刪除,所以我假定這就是問題所在:cuvAfisat = cuvAfisat.substring(0, poz*2-1)+ ghici+ cuvAfisat.substring(poz*2+1, cuvAfisat.length());
(它是一個從cuvAles更換從cuvAfisat字符,但它在每個角色之間都有空格,所以這就是爲什麼它有poz * 2。
謝謝您的幫助!
編輯:
07-01 12:31:09.723: E/AndroidRuntime(12530): FATAL EXCEPTION: main
07-01 12:31:09.723: E/AndroidRuntime(12530): java.lang.IllegalStateException: Could not execute method of the activity
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.view.View$1.onClick(View.java:2144)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.view.View.performClick(View.java:2485)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.view.View$PerformClick.run(View.java:9080)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.os.Handler.handleCallback(Handler.java:587)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.os.Handler.dispatchMessage(Handler.java:92)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.os.Looper.loop(Looper.java:123)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-01 12:31:09.723: E/AndroidRuntime(12530): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 12:31:09.723: E/AndroidRuntime(12530): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 12:31:09.723: E/AndroidRuntime(12530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 12:31:09.723: E/AndroidRuntime(12530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 12:31:09.723: E/AndroidRuntime(12530): at dalvik.system.NativeStart.main(Native Method)
07-01 12:31:09.723: E/AndroidRuntime(12530): Caused by: java.lang.reflect.InvocationTargetException
07-01 12:31:09.723: E/AndroidRuntime(12530): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 12:31:09.723: E/AndroidRuntime(12530): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 12:31:09.723: E/AndroidRuntime(12530): at android.view.View$1.onClick(View.java:2139)
後全logcat的堆棧跟蹤 –
安置自己的onClick()方法。 –