Я делаю проект для своей школы, и я обрабатываю все исключения, но я просто не могу справиться с ArrayOutOfBoundsException. , так что я искал решение в stackoverflow, и он говорит, что использует IndexOutOfBoundsException (ссылка на решение: why is it not catching the arrays out of bound?) , но он не работал. пожалуйста помоги? вот мой код:catching ArrayOutOfBoundsException
for (int i = 0; i < 4; i++) {
System.out.println(fruit[i] + fruitprice[i]);
}
System.out.println("\n" + "please enter the number marked for the icecream you want to buy");
do {
x = 0;
try {
icenum1 = Integer.parseInt(in .readLine()) - 1;
} catch (NumberFormatException n) {
System.out.println("please enter in numbers and not in words.... please try again");
x = 1;
} catch (IndexOutOfBoundsException e) {
System.out.println("please enter a number out of the given numbers and not any other number");
x = 1;
}
} while (x != 0);
System.out.print("\u000c");
System.out.println("your choice is " + fruit[icenum1]);
Вам нужно использовать тип массива или коллекцию, чтобы получить это исключение. Где вы используете его в своем блоке try? –
@YassinHajaj Я делаю проект, который в настоящее время составляет 512 строк, и я действительно новичок в этом, поэтому ... – vtsin
Да, это не проблема. Мы все были там, мой вопрос был не саркастичным, а был всего лишь способом найти правильный путь к решению проблемы. :) –