获取 java.lang.ClassCastException: [Ljava.lang.Object; 不能转换为 [LBlndItmTmMthd
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3290430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
提问by rajshekhar
I need a serious help in this issue. May be its very basic, but, I am not able to figure it out. I have a session EJB with one method which returns an enum array, i.e. BlndItmTmMthdarray. When, I call the method in the client side, it gives me a ClassCastException.
在这个问题上我需要一个认真的帮助。可能是非常基本的,但是,我无法弄清楚。我有一个会话 EJB,其中一个方法返回一个枚举数组,即BlndItmTmMthd数组。当我在客户端调用该方法时,它给了我一个ClassCastException.
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
While debugging, I have found that the ejb method is correctly returning BlndItmTmMthdarray by calling BlndItmTmMthd.values(). I am not able to find out the reason. Any idea will be helpful.
在调试时,我发现 ejb 方法BlndItmTmMthd通过调用BlndItmTmMthd.values(). 我无法找出原因。任何想法都会有所帮助。
Added content from a comment below
AgreementSession.java is the EJB interface which contains the following method declaration:
从
AgreementSession.java下面的评论中添加的内容是包含以下方法声明的EJB接口:
BlndItmTmMthd[] getAllBlendedItemTimingMethods();
AgreementSessionEJB.java is the EJB that implements it.
AgreementSessionEJB.java 是实现它的 EJB。
public BlndItmTmMthd[] getAllBlendedItemTimingMethods() {
BlndItmTmMthd[] blendedItemTmingMethods = BlndItmTmMthd.values();
return blendedItemTmingMethods;
}
Now, at the client side, when I invoke the EJB method with the following code:
现在,在客户端,当我使用以下代码调用 EJB 方法时:
BlndItmTmMthd[] _timingMethods =
getLoanScheduleSetupSession().getAllBlendedItemTimingMethods();
I get that runtime exception.
我得到那个运行时异常。
采纳答案by Sbodd
The "[L" in your error tells you the problem - Java is failing to cast an arrayof Objects (that is, an Object[]) to an array of BlndItmTmMthds (a BlndItmTmMthd[]).
错误中的“[L”告诉您问题-Java 无法将对象数组(即对象 [])转换为 BlndItmTmMthds 数组(BlndItmTmMthd[])。
Is BlndItmTmMthd really a java.lang.Enum?
BlndItmTmMthd 真的是 java.lang.Enum 吗?
回答by Roland Illig
I assume that you have access to both the server and the client code. To trace down this issue you should insert logging statements of the form
我假设您可以访问服务器和客户端代码。要跟踪此问题,您应该插入表单的日志记录语句
logger.info(array.getClass().getCanonicalName());
at all places on the way from the BlndItmTmMthdto the Object. Then you can at least say at which point the conversion happens.
从BlndItmTmMthd到途中的所有地方Object。然后你至少可以说转换发生在什么时候。
回答by Vineet Reynolds
Given that the error implies that there is a failure to cast objects of type java.lang.Object to the Enum class, I believe there is a failure in the serialization and deserialization process when the response from the EJB is received at the client.
鉴于该错误暗示将 java.lang.Object 类型的对象转换为 Enum 类失败,我相信在客户端收到来自 EJB 的响应时,序列化和反序列化过程中存在失败。
There are a couple of things that you might want to check:
您可能需要检查以下几项内容:
- Is the Enum class BlndItmTmMthd available in the same classloader, or is it loaded twice?
- Does the generated stub of the EJB contain references to the Enum class or to java.lang.Object?
- 枚举类 BlndItmTmMthd 在同一个类加载器中可用,还是加载了两次?
- 生成的 EJB 存根是否包含对 Enum 类或 java.lang.Object 的引用?

