You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Drag and DropTarget Grids时遇ArrayIndexOutOfBoundsError求解决

Codename One MorphAnimation数组越界问题

我用Drag and Drop功能在屏幕上移动角色,记录位置后播放角色移动到对应网格位置的动画。该功能已正常运行一年半,最终测试中执行了以下操作:

  • 创建空白存储数据库副本
  • 重启应用将数据库写入模拟器内存
  • 运行MoveByDrag类

移动24个角色中的第一个时,模拟器直接卡死,需强制退出,同时触发如下错误:

[EDT] 0:0:29,715 - Exception: java.lang.ArrayIndexOutOfBoundsException - Index 0 out of bounds for length 0

堆栈跟踪信息:

Index 0 out of bounds for length 0

错误调用链首行:

at com.codename1.ui.Container$MorphAnimation.updateState(Container.java:4335)

对应Container.java中MorphAnimation的updateState方法最后一行代码:

@Override
protected void updateState() {
    if(animatedComponents != null) {
        int componentCount = animatedComponents.size();
        for(int iter = 0 ; iter < componentCount ; iter++) {
            Component currentCmp = (Component)animatedComponents.elementAt(iter);

            currentCmp.setX(motions[0][iter].getValue());
            currentCmp.setY(motions[1][iter].getValue());
            currentCmp.setWidth(motions[2][iter].getValue());
            currentCmp.setHeight(motions[3][iter].getValue());

编辑1:Intellij指出setHeight是错误的起始关联点。

请问有谁遇到并解决过该问题?

内容的提问来源于stack exchange,提问作者curtjacobs1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 03:42:07