try-catch - java捕获indexoutofbounds异常
问题描述
我用谷歌搜索了很多,但我不知道为什么我无法捕捉到indexoutofboundsexception
错误。有人可以告诉我,我的错误是什么?
try
{
if (amountOfPlayers <= 15 && amountOfPlayers > 0) {
int i = 0;
do {
i++;
System.out.println("Please enter your name: ");
String name = scanner.next();
nameList.add(name);
} while (i < amountOfPlayers);
}
}
catch (IndexOutOfBoundsException ex)
{
System.out.println("Wrong input. Theres a maximum of 15 players allowed");
}
解决方案
推荐阅读
- python - Python Dash - 可以循环创建 dbc.Row 吗?
- typescript - 如何在 VSCode 扩展的文件中插入文本
- flutter - Flutter - 禁用导航 InAppWebView
- android - 多个片段的一个 ViewModel 实例
- sap-cloud-sdk - 租户特定的弹性配置
- android - 主要要求是将 react-native-android 构建转换为 .aar(Android Archive) 库以在 Cordova 中重用
- autosar - 如何在 Vector AUTOSAR 配置工具中为 OS_Task 配置 MPU(内存保护单元)?
- ios - 如何在父视图中将项目添加到全局列表 var initted/wrapped 在 ObservableObject 中并让它在子视图中反映在 SwiftUI 中的 ForEach 中?
- django - 值错误:字段 'id' 需要一个数字,但得到了 'favicon.ico
- javascript - 为什么动画不适用于所有类元素?