【问题标题】:Exception in thread "main" java.lang.IndexOutOfBoundsException线程“主”java.lang.IndexOutOfBoundsException 中的异常
【发布时间】:2011-07-05 04:41:32
【问题描述】:

我正在传递这种类型的数组:-

Integer[] A={32,543,423};
Integer[] B={32,43};

到方法:

public void method1(K[] Items1, N[] Items2, integerSerializerObject){  
    method2(Items1, Items2);               // this method again passes on the parameters to method2 & method3
}

传递给:-

public void method2(K... things1){  
}   

public void method3(N... things2){  
}  

method2 & method3 实际上属于一个名为 Hector 的库,用于访问 Cassandra DB,因此错误不存在,而是在我自己的代码中,仅在此方法之上。我将这两个数组与 IntegerSerializer 对象一起传递,以将这些数组元素转换为字节。完整列表异常详情如下:(但我觉得这个bug在我的代码中而不是在库函数中,因此可能在我的代码中可见)

我收到一条异常消息:-

  Exception in thread "main" java.lang.IndexOutOfBoundsException
        at java.nio.Buffer.checkIndex(Buffer.java:514)  
        at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:121)  
        at me.prettyprint.cassandra.serializers.IntegerSerializer.fromByteBuffer(IntegerSerializer.java:42)  
        at me.prettyprint.cassandra.serializers.IntegerSerializer.fromByteBuffer(IntegerSerializer. java:12)
        at me.prettyprint.cassandra.serializers.AbstractSerializer.fromBytesMap(AbstractSerializer.java:115)
        at me.prettyprint.cassandra.model.thrift.ThriftMultigetSliceQuery$1.doInKeyspace(ThriftMultigetSliceQuery.java:67)
        at me.prettyprint.cassandra.model.thrift.ThriftMultigetSliceQuery$1.doInKeyspace(ThriftMultigetSliceQuery.java:59)
        at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20)
        at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:65)
        at me.prettyprint.cassandra.model.thrift.ThriftMultigetSliceQuery.execute(ThriftMultigetSliceQuery.java:58)

你们知道我哪里做错了吗?

【问题讨论】:

  • 如果您希望我们猜测异常所在的位置,也许您应该发布更多代码。
  • 显示您在数组中迭代的代码部分。您可能超出了数组的大小
  • 需要完整的代码。请张贴。
  • 我没有对数组进行迭代,我已经将整数数组传递给库方法,同时传递了序列化器对象(对于整数类型),该对象将其转换为字节,然后将其存储在数据库中.也许库中序列化此数组元素的方法正在抛出异常。
  • 你的问题非常不完整,在你发布更多代码之前你不会得到一个好的答案。错误在IntegerSerializer 中,并且在堆栈跟踪(至少您发布的内容)中没有提到method1 和method2。请发布所有代码。

标签: java arrays generics exception


【解决方案1】:

据我所知,可变参数只能用于最后一个参数。正如本网站所述:

Varargs 只能在 final 中使用 论据位置。

(http://download.oracle.com/javase/1.5.0/docs/guide/language/varargs.html)

这会产生你的例外吗?

【讨论】:

    猜你喜欢
    • 2012-10-23
    • 2018-10-29
    • 2017-01-02
    • 2016-01-12
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多