我有一个Logcat error report
我无法理解的。你能帮帮我吗?我是 Android 应用程序开发的新手!
07-10 08:51:42.603: E/AndroidRuntime(791): FATAL EXCEPTION: main
07-10 08:51:42.603: E/AndroidRuntime(791): java.lang.ArrayIndexOutOfBoundsException: length=26; index=26
07-10 08:51:42.603: E/AndroidRuntime(791): at com.example.hangman.Play$1.onClick(Play.java:70)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.view.View.performClick(View.java:4204)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.view.View$PerformClick.run(View.java:17355)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.os.Handler.handleCallback(Handler.java:725)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.os.Looper.loop(Looper.java:137)
07-10 08:51:42.603: E/AndroidRuntime(791): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-10 08:51:42.603: E/AndroidRuntime(791): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 08:51:42.603: E/AndroidRuntime(791): at java.lang.reflect.Method.invoke(Method.java:511)
07-10 08:51:42.603: E/AndroidRuntime(791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 08:51:42.603: E/AndroidRuntime(791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-10 08:51:42.603: E/AndroidRuntime(791): at dalvik.system.NativeStart.main(Native Method)
我的 OnClickListener() 代码如下: View.OnClickListener go_func = new View.OnClickListener() {
@Override
public void onClick(View v) {
int flag = 0;
TextView status = (TextView) findViewById(R.id.status);
TextView chances = (TextView) findViewById(R.id.chances);
TextView word = (TextView) findViewById (R.id.word);
EditText guessed = (EditText) findViewById(R.id.letter_guessed);
String letter = guessed.getText().toString();
char[] Letter = letter.toCharArray();
String current_status = status.getText().toString();
String current_chances = chances.getText().toString();
String current_word = new String();
//checking if letter is already guessed
for(int i=0;i<letters_guessed.length;i++)
{
if(Letter[0] == letters_guessed[i])
{
current_status = "Letter Already Guessed!";
status.setText(current_status);
}
break;
}
//if letter is not already guessed
if(current_status !="Letter Already Guessed!")
{
int len=0;
int i=0;
while(letters_guessed[i] != '\u0000')
{
len++;
i++;
}
if(len !=0)
letters_guessed[len] = Letter[0];
else
letters_guessed[0] = Letter[0];
for(i=0;i<word_chosen.length();i++)
{
flag = 0;
for(int j=0;j<letters_guessed.length;j++)
{
if(word_final[i]==letters_guessed[j])
{
char[] temp_array = current_word.toCharArray();
temp_array[temp_array.length] = word_final[i];
current_word = temp_array.toString();
flag=1;
break;
}
}
if(flag==0)
{
char[] temp_array = current_word.toCharArray();
temp_array[temp_array.length] = '_';
current_word = temp_array.toString();
}
}
}
int a=0;
char[] word_check = word_chosen.toCharArray();
for(int i=0;i<word_check.length;i++)
{
if(word_check[i] == Letter[0])
{
a=1;
status.setText("Correct guess!");
}
}
if(a==0)
{
status.setText("Wrong guess!");
}
word.setText(current_word);
}
};