gpt4 book ai didi

Java 中的 java.lang.reflect.InitationTargetException

转载 作者:行者123 更新时间:2023-12-01 17:39:23 30 4
gpt4 key购买 nike

if(locs!=null)
{
System.out.println("location are not null");
Iterator ite = locs.iterator();
DefaultComboItem locObj = null;
ArrayList locCode = null;
String cod=null;
String name=null;
while(ite.hasNext())
{
locCode = (ArrayList) ite.next();
Iterator iter = locCode.iterator();
while(iter.hasNext())
{
cod=(String)iter.next();
System.out.println("Code="+cod);
name=(String)iter.next();
System.out.println("name="+name);
locObj = new DefaultComboItem(cod, name);
colRet.add(locObj);
}
}

}

在执行上面的代码时,我收到“java.lang.reflect.InitationTargetException”获取此异常 cod=(String)iter.next();行,因为 iter.next();返回 bigDecimal 值,我正在转换为字符串变量

请帮助我

最佳答案

您调用了 next() 两次,但在 while 循环条件中仅检查 hasNext() 一次。如果您的列表包含奇数个元素,则此代码将抛出 NoSuchElementException,该异常可能会被包装在 InitationTargetException 中的某处。

关于Java 中的 java.lang.reflect.InitationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2920058/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com