String[] lvl15={"Twin", "Flank Guard", "Sniper", "Machine Gun"};
String[] lvl30={"", "Triple Shot", "Quad Tank", "Twin Flank", "Tri-Angle", "Assasin", "Overseer", "Hunter", "Destroyer", "Gunner", ""};
String[] lvl45={"Triplet", "Penta Shot", "Octo Tank", "Triple Twin", "Overlord", "Necromancer"};
int index15;
int index30;
int index45;
index15=rand.nextInt(lvl15.length);
switch(index15){
case 0: class15="Twin";
break;
case 1: class15="Flank Guard";
break;
case 2: class15="Sniper";
break;
case 3: class15="Machine Gun";
break;
}
if(class15=="Twin"){index30=rand.nextInt(3)+1; class30=lvl30[index30];}
if(class15=="Flank Guard"){index30=rand.nextInt(4)+2; class30=lvl30[index30];}
if(class15=="Sniper"){index30=rand.nextInt(7)+5; class30=lvl30[index30];}
if(class15=="Machine Gun"){index30=rand.nextInt(9)+8; class30=lvl30[index30];}
コードがあります。何らかの理由で、それはそうなので、これはウェイライン54によって理由もなくあるように時々 ランダマイザーが機能しなくなり、エラーが発生する
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
at diepiogen.DiepIOGen.main(DiepIOGen.java:54)
C:\Users\******\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
だから、誰かがあれば(class15 ==「スナイパー」){index30 =ランドが助けてくださいすることができます。このエラーを思い付きます.nextInt(7)+5; class30 = lvl30 [index30];}
これで、フィラーを追加するだけです。
配列のサイズは11で、インデックスは0から10になります...エラーは、存在しないインデックス「11」を使用していることを示します。 – sinclair
'if(class15 ==" Twin ")' [Javaで文字列を比較するには?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) - コンパイル時に知られている文字列リテラルを比較しているので、この部分がうまくいくかもしれませんが、実際には '=='を使って文字列を比較するのをやめてください(特に、作成した文字列実行時に)。 – Pshemo
クラスの乱数生成で配列の範囲を超えています – Li357