public class ItemTable {
private final Integer[] idT = { 1,2,3,4,5,6,7,8,9,10 };
private final Integer[] quantityT = { 1,2,3,4,5,6,7,8,9,10 };
private final String[] barcodeT = { "001" , "002", "003", "004", "005",null,null,null,null,null, };
private final String[] nameT = { "Milk", "Bread", "Wine", "Butter", "Potato", "Sweet Potato","Ginger" ,"Avacado", "Cucumber"};
private final double[] perWeightT = {0.2,0.4,0.1,0.2,0.1,2,1,0.5,0,0,0};
private final double[] perPriceT = { 1.50, 2.45, 12.95, 4.75, 2, 3.5, 12, 4, 3, 1 };
private final ArrayList<ItemType> table = new ArrayList<>();
public final ArrayList<View> lookUpItem = new ArrayList<>();
public ItemTable()
{
for(int i = 0; i< idT.length; i++)
{
if(barcodeT[i]!=null)
table.add(new ItemTypeB (idT[i], nameT[i], perPriceT[i],perWeightT[i],barcodeT[i]));
else
{
if(perWeightT[i]!=0)
{
table.add(new ItemTypeW(idT[i], nameT[i], perPriceT[i],perWeightT[i],perWeightT[i]));
lookUpItem.add(new View(idT[i], nameT[i], "w"));
}
if(perWeightT[i]==0)
{
table.add(new ItemTypeC(idT[i], nameT[i], perPriceT[i],perWeightT[i], quantityT[i]));
lookUpItem.add(new View(idT[i], nameT[i], "c"));
}
}
}
}
問題の領域は、コードの最後の行を中心に具体的にはtable.add(new ItemTypeC)
です。スレッド "main"の例外java.lang.ArrayIndexOutOfBoundsException:9
ヒントをスロー:あなたが反復され、各上の表にどのように多くの要素であり、そしてあなたは、各反復で使用しているテーブルの残りの部分にどのように多くの要素がありますか? – Pshemo
あなたの質問の周りに「助けてください」という言葉を入れる必要はありません。これは特にタイトルの場合です - タイトルを有益かつ簡潔に保ってください。ありがとう! – halfer