java - 为什么我有这个错误?ArrayIndexOutOfBoundsException
问题描述
我正在创建一个安卓应用程序。当我在 Emulator、Samsung S8 Plus 和 General Mobile GM8 中进行测试时,我没有任何错误,但游戏机总是让我有些迷恋。
代码是:
int count = getItemCount() >= 30 ? 30 : getItemCount();
if (count == 0)
return new long[] {0};
long[] result = new long[count];
for (int i = 0; i < count; i++)
result[i] = users.get(i).getPk();
return result;
错误消息: ArrayIndexOutOfBoundsException
我怎么能解决它我真的不知道。
解决方案
删除“=”符号以使其正常工作:
int count = getItemCount() > 30 ? 30 : getItemCount();
if (count == 0)
return new long[] {0};
long[] result = new long[count];
for (int i = 0; i < count; i++)
result[i] = users.get(i).getPk();
return result;
推荐阅读
- python - flask test_client 为有效的 url 返回 404
- sas - 如何使规范的 PROC CALIS LINEQS 示例工作?
- html - 提供使用 HTML 将项目添加到日历的选项 - 仅限 Outlook
- javascript - 计算 2 个数组中的每个值,如果每个数组的长度不同,则推送具有较长长度的值
- r - 根据时间查找两个目录(在十分钟的 bin 中)。恶魔般的目录灾难
- vb.net - 如何限制 GetFiles 以获取在某个日期之后创建的所有路径?
- html - 为什么 Firefox 忽略 css :hover 选择器?
- apache-kafka - 无法消费来自 ClickHouse 中主题分区的消息
- javascript - 如何在restify应用程序中使用passportjs中间件
- bash - 在 SLURM 之外使用 srun