Java 获得ArrayIndexOutboundsException的数组索引

Java 获得ArrayIndexOutboundsException的数组索引,java,swing,Java,Swing,我从数据库中获取时间、值、权重,相关方法在ExperimenalImpl中可用。这些值显示在表格中。当我们选择特定的行时,相关的getXxx()方法将调用。但有些行正确地获取了数据。只有一行出现此异常 Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method)

我从数据库中获取时间、值、权重,相关方法在ExperimenalImpl中可用。这些值显示在表格中。当我们选择特定的行时,相关的getXxx()方法将调用。但有些行正确地获取了数据。只有一行出现此异常

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException
            at java.lang.System.arraycopy(Native Method)
            at com.integrativebioinformatics.processdb.pdbnt.IBExperimentalDataImpl.getWeights(IBExperimentalDataImpl.java:103)
            at com.insilicalabs.processdb.ui.controllers.ExperimentalDataController.showExperiment(ExperimentalDataController.java:197)
            at com.insilicalabs.processdb.ui.controllers.ExperimentalDataController.showExperimentAtIndex(ExperimentalDataController.java:184)   
代码:

public void setWeights(双倍重量){
if(experimentweights==null)抛出新的IllegalArgumentException(“不能接受null参数”);
this.experimentweights=新的双精度[experimentweights.length];
System.arraycopy(实验重量,0,此。实验重量,0,实验重量。长度);
对于(int i=0;i)观察,它表示:

Otherwise, if any of the following is true, an IndexOutOfBoundsException is thrown and the destination is not modified:

The srcPos argument is negative.
The destPos argument is negative.
The length argument is negative.
srcPos+length is greater than src.length, the length of the source array.
destPos+length is greater than dest.length, the length of the destination array. 

首先,我要调试您的程序,看看出现了哪种情况。

您使用此长度
this.experimentTimeValuePairs[0]。长度
分配
newWeights
数组

但是在
arrayCopy
中,您使用的是
this.experimentweights.length


您可能应该使用
this.experimentweights.length
分配
新权重
,因为这就是您要复制的内容。

-1在4个问题之后,您应该知道如何正确设置问题的格式。
ArrayIndexOutOfBounds
是一个非常明显的例外。在某些地方,您使用的索引位于数组bou之外如果你想成为一名程序员,你必须学会自己调试这些简单的异常和错误。
newWeights[i]=(0.0D/0.0D)
该死,这太糟糕了:除了所有评论之外,请至少发布一个SSCCE。如果我们可以在不损失这么多时间的情况下运行您的代码,一个快速的答案将是可能的。我同意@PetarMinchev,这是一个非常清楚、直接的错误。另外,
(0.0D/0.0D)
,请不要这样做,哈哈:-)
Otherwise, if any of the following is true, an IndexOutOfBoundsException is thrown and the destination is not modified:

The srcPos argument is negative.
The destPos argument is negative.
The length argument is negative.
srcPos+length is greater than src.length, the length of the source array.
destPos+length is greater than dest.length, the length of the destination array.