問題がヌルポインタと関連しているスレッドの例外「メイン」。存在しない文字列のデータを受け取ろうとしています。問題の定義は単純で、解決方法は非常に簡単なので、forループの文字列の長さを制御する必要があります。あなたのコードをもう一度チェックしてください。あなたはこのヌルに直面しているように、ループのために、あなたはちょうど私の変数をインクリメントj変数をインクリメントされませんが、jは常にゼロであるあなたの
EDIT
ルックはので、私の変数は、常にforループによってインクリメントポインタ例外。
EDIT2
public static String[] wordArray(int wordAmount){
String[] words = new String[wordAmount];
Scanner input = new Scanner(System.in);
for(int i = 0; i < wordAmount; i++){
System.out.print("Enter a word: ");
words[i] = input.nextLine();
for(int j = 0; j < wordAmount; j++){
//boolean tt = words[i].contains("selam");
if(j == 1) break;
System.out.println(words[i].contains(words[j]));
//System.out.println(tt);
if(words[i].contains(words[j]) & (i != j)){ ///////////////////
System.out.print("The word you entered has already been entered, enter a new word: ");
words[i] = input.nextLine();
}
}
while(words[i].length() > 10 | words[i].length() <= 1 | words[i].contains(" ")){
System.out.print("The word you entered has been rejected, enter a new word: ");
words[i] = input.nextLine();
}
}
return words;
}
これを試してみて、何が起こっているかご覧ください。 。 。 stringobject.length()によって文字列の長さを取得する必要がある主な問題です。それで、もし私が上で書いたブロックであれば、それを制御する必要があります。だから問題はなくなります。
はEDIT3
より明確な答えは、あなたが
public static String[] wordArray(int wordAmount){
String[] words = new String[wordAmount];
Scanner input = new Scanner(System.in);
for(int i = 0; i < wordAmount; i++){
System.out.print("Enter a word: ");
words[i] = input.nextLine();
int len = i;
for(int j = 0; j < wordAmount; j++){
//boolean tt = words[i].contains("selam");
if(j == i) break;
System.out.println(words[i].contains(words[j]));
//System.out.println(tt);
if(words[i].contains(words[j]) & (i != j)){ ///////////////////
System.out.print("The word you entered has already been entered, enter a new word: ");
words[i] = input.nextLine();
}
}
while(words[i].length() > 10 | words[i].length() <= 1 | words[i].contains(" ")){
System.out.print("The word you entered has been rejected, enter a new word: ");
words[i] = input.nextLine();
}
}
return words;
}
こんにちはデヴィンのために、私はまた、あなたはあなたを助けるために多くの人々を得るために作業している言語タグをお勧めします。 – micstr
@aidanリンクはC++ –