Cannot be cast to class because they are in unnamed module of loader 'app'
Solution 1
I had a similar case, and (as mentioned by @Holger in the comment) the module info in the message is simply misleading - this is an actual case of trying to cast something to something that doesn't match it.
In your case, ClientImpl
simply is not a subtype of XigniteCurrenciesSoap
.
Solution 2
The stacktrace is trying to tell you that you have casted XigniteCurrenciesSoap
to ClientImpl
.
Such as the example below:
Object returnObj= getXigniteCurrenciesSoap();
return (ClientImpl) returnObj;
You have to find out where you did that in your code and fix it.
Related videos on Youtube
Cisco
The statements I make here are my own and do not represent those of Discover Financial Services I am not speaking on behalf of Discover Financial Services or any other company.
Updated on May 06, 2022Comments
-
Cisco about 2 years
I'm trying to create a bean from sources that were generated by
wsdl2java
.Every time I try to run my Spring Boot app, I get the following error:
Caused by: java.lang.ClassCastException: class org.apache.cxf.endpoint.ClientImpl cannot be cast to class com.xignite.services.XigniteCurrenciesSoap (org.apache.cxf.endpoint.ClientImpl and com.xignite.services.XigniteCurrenciesSoap are in unnamed module of loader 'app')
I'm not sure how exactly I'm to include generated sources in my main Spring Boot application as a module.
My directory structure is:
├── build │ └── generatedsources │ └── src │ └── main │ └── java │ └── com │ └── xignite │ └── services │ └── src └── main ├── java │ └── io │ └── mateo │ └── stackoverflow │ └── soapconsumption └── resources └── wsdls
Relevant system info:
openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
- Spring Boot 2.1.2.RELEASE
- Gradle 5.2
I've also uploaded the project onto Github here: https://github.com/ciscoo/soap-consumption-spring-boot
-
Naman over 5 yearsnot very sure about wsdl here...but, did you try adding a
module-info.java
to your project and/or ensure that the module you're depending upon (for classesorg.apache.cxf.endpoint.ClientImpl
) is resolved on the modulepath rather than the classpath. -
Holger about 5 yearsThere is no “because” in the error message. All this addendum tells you, is, that both classes are located in the same module, the unnamed module of loader 'app', which helps the reader to understand that this problem is entirely unrelated to modules.
ClientImpl
simply is not a subtype ofXigniteCurrenciesSoap
; it's an ordinaryClassCastException
. -
Saman Salehi almost 3 yearsIn my case it was a little bit different. Class Cast Exception sometime happen because of the conflict between different version of the java. in pom.xml i set to use "<java.version>1.8</java.version> but in Intellje IDE i set to use java version 11. after changing java version from 11 to 8 problem solved for me.
-
Maarten Meeusen over 4 yearsI had a similar problem and thought it was impossible to be a ClassCastException. After finding this answer I properly examed the exception again and it turned out I was extending from a superclass with a same name in a different package. So even though it might look like a different problem, it really is a ClassCastException.
-
Cisco over 3 yearsAt the time I asked the question, I was still fairly new with Apache CXF. The reason for the class cast exception was because I was using JaxWsClientFactoryBean instead of JaxWsProxyFactoryBean. The former returns a ClientImpl while the latter returns a proxy that you must cast. I'm working on something new for work and remembered this question.
-
cd491415 over 2 yearsIn my case, I am trying to convert List<Object> to List<MyInterface> and am getting same problem
-
Dan about 2 yearsThis does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review