I'm creating a jumbled word game. At first I only have 3 levels, but when I try to add another levels, I got this error " java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 "
This part is where the error
@Override
protected void onResume() {
super.onResume();
final String [] str=quesWord.toArray(new String[quesWord.size()]);
attemptsLeft.setText("Attempts left: "+chances);
points.setText("Score: "+score);
jumbleWord.setText(wordJumble(str[0]));
b.setOnClickListener(new OnClickListener() {
int j=0;
int len=str.length;
public static String wordJumble(String word )
{
Random random = new Random();
char wordArray[] = word.toCharArray();
for(int i=0 ; i< wordArray.length-1 ; i++ )
{
int j = random.nextInt(wordArray.length-1);
char temp = wordArray[i];
wordArray[i] = wordArray[j];
wordArray[j] = temp;
}
if(wordArray.toString().equals(word)){
wordJumble(word);
}
return new String(wordArray);
}
public void fetchWords(){
try{
c=db.rawQuery("select * from wordscramble where level='"+lv+"'",null);
while(c.moveToNext()){
s=c.getString(0);
quesWord.add(s);
}
Collections.shuffle(quesWord);
}
catch(Exception e){
}
}