我遇到了这个异常,但描述对我一点帮助都没有:
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)