简体   繁体   English

尝试在翡翠中打印容器ID时出现java.lang.ClassCastException

[英]java.lang.ClassCastException while trying to print container id in jade

I have a code for finding the list of containers from the ams in jade using queryPlatformAction method. 我有一个代码,可以使用queryPlatformAction方法从玉器中的ams查找容器列表。 I am getting a problem for typecasting the container id while putting the sop statement at the end.. 在将sop语句放在末尾时,我在类型转换容器ID时遇到问题。

     Result result = (Result) content;
     List listOfPlatforms = (List) result.getValue();
     Iterator iter = listOfPlatforms.iterator();
     while (iter.hasNext()) 
       {
       ContainerID next = (ContainerID) iter.next();
       System.out.println(next.getID());
       }

It is throwing an exception to me. 这给我带来了例外。

The exception is: java.lang.ClassCastException: jade.util.leap.ArrayList cannot be cast to java.util.List please help. 例外是:java.lang.ClassCastException:jade.util.leap.ArrayList无法强制转换为java.util.List,请帮助。

The two types of List are not in the same class hierarchy and therefore cannot be cast between each other, hence a ClassCastException . 两种类型的List不在同一类层次结构中,因此不能在彼此之间ClassCastException ,因此是ClassCastException

The jade.util.leap.List interface is used within JADE to provide a List collection that looks the same between the different back-ends of JADE, but which is actually implemented differently. JADE中使用jade.util.leap.List接口提供一个List集合,该List集合在JADE的不同后端之间看起来相同,但实际上实现方式不同。 From the Javadocs, ArrayList only extends Object . 从Javadocs开始, ArrayList仅扩展Object

To fix this, declare listOfPlatforms to be of type jade.util.leap.List . 为了解决这个问题,声明listOfPlatforms为类型jade.util.leap.List

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM