我得到了这个例外,但描述对我没有任何帮助:
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());
(它将cuvAfisat中的一个字符替换为cuvAles中的一个字符,但它有每个角色之间的空格,这就是为什么它有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)
答案 0 :(得分:0)
我不完全明白你在这里想做什么。
但逻辑对我来说有点奇怪。
如果poz = 0,将不会出现以下情况?
cuvAfisat.substring(0, poz*2-1)
此外,你能确定poz的价值
不会使poz*2+1
超过cuvAfisat.length()