获取 java.lang.ClassCastException: [Ljava.lang.Object;无法转换为 [LBlndItmTmMthd
在这个问题上我需要认真的帮助。可能这是非常基本的,但是,我无法弄清楚。我有一个会话 EJB,它有一个返回枚举数组的方法,即 BlndItmTmMthd
数组。当我在客户端调用该方法时,它会给我一个 ClassCastException
。
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
在调试时,我发现 ejb 方法通过调用 BlndItmTmMthd.values()
正确返回 BlndItmTmMthd
数组。我无法找出原因。任何想法都会有所帮助。
添加了下面评论中的内容
ContractSession.java 是 EJB 接口,其中包含以下方法声明:
BlndItmTmMthd[] getAllBlendedItemTimingMethods();
ContractSessionEJB.java 是实现它的 EJB。
public BlndItmTmMthd[] getAllBlendedItemTimingMethods() {
BlndItmTmMthd[] blendedItemTmingMethods = BlndItmTmMthd.values();
return blendedItemTmingMethods;
}
现在,在客户端,当我使用以下代码调用 EJB 方法时:
BlndItmTmMthd[] _timingMethods =
getLoanScheduleSetupSession().getAllBlendedItemTimingMethods();
我得到了运行时异常。
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. BlndItmTmMthd
array. When, I call the method in the client side, it gives me a ClassCastException
.
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
While debugging, I have found that the ejb method is correctly returning BlndItmTmMthd
array by calling BlndItmTmMthd.values()
. I am not able to find out the reason. Any idea will be helpful.
Added content from a comment below
AgreementSession.java is the EJB interface which contains the following method declaration:
BlndItmTmMthd[] getAllBlendedItemTimingMethods();
AgreementSessionEJB.java is the EJB that implements it.
public BlndItmTmMthd[] getAllBlendedItemTimingMethods() {
BlndItmTmMthd[] blendedItemTmingMethods = BlndItmTmMthd.values();
return blendedItemTmingMethods;
}
Now, at the client side, when I invoke the EJB method with the following code:
BlndItmTmMthd[] _timingMethods =
getLoanScheduleSetupSession().getAllBlendedItemTimingMethods();
I get that runtime exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误中的“[L”告诉您问题 - Java 无法将对象数组(即 Object[])转换为 BlndItmTmMthds 数组(BlndItmTmMthd[])。
BlndItmTmMthd 真的是 java.lang.Enum 吗?
The "[L" in your error tells you the problem - Java is failing to cast an array of Objects (that is, an Object[]) to an array of BlndItmTmMthds (a BlndItmTmMthd[]).
Is BlndItmTmMthd really a java.lang.Enum?
鉴于该错误意味着将 java.lang.Object 类型的对象转换为 Enum 类失败,我相信当客户端收到来自 EJB 的响应时,序列化和反序列化过程出现故障。
您可能需要检查以下几件事:
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.
There are a couple of things that you might want to check:
我假设您可以访问服务器和客户端代码。要追踪此问题,您应该
在从
BlndItmTmMthd
到Object
的所有位置插入表单的日志记录语句。然后你至少可以说出转换发生的时间点。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
at all places on the way from the
BlndItmTmMthd
to theObject
. Then you can at least say at which point the conversion happens.