Questions tagged [classcastexception]
The Java exception thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
1,663
questions
0
votes
1
answer
13
views
Why am I getting this ClassCastException during an assignment where the two types are the same? (Groovy / Hibernate)
I have the following classes defined:
enum FruitTypeEnum {
APPLE,
BANANA,
NONE
}
// POGO
class FruitDTO {
FruitTypeEnum fruitType
}
// Hibernate Entity
abstract class Farm {
...
1
vote
0
answers
61
views
How can I do what I think this code is doing without getting a ClassCastException?
I have read other similar questions on StackOverflow but do not understand the root cause, and can't figure out a fix on my own. Could you help me understand what the issue is?
Here is my code:
List&...
0
votes
0
answers
26
views
ClassCastException: Object turning into Google Gson LinkedTreeMap
I have a User class, where all data about a unique User is stored.
@AllArgsConstructor
public class User {
private Map<String, Object> extras;
// other fields
public Map<String, ...
0
votes
1
answer
62
views
Strange behaviour with ClassCastException at runtime
I am using Mapstruct to map convert one POJOs to another POJO model
Following is the method that mapstruct auto generated
protected Map<String, GenericAttributeData> ...
0
votes
0
answers
24
views
Liquibase ClassCastException on LiquibaseConfiguration when running update on MongoDB
Below jars are present on the classpath
mongo-java-driver-3.12.11.jar
liquibase-mongodb-4.11.0.jar
liquibase-core-4.11.0.jar
[2022-06-17 12:54:30] SEVERE [liquibase.integration] Unexpected error ...
-3
votes
0
answers
22
views
why it cause an ClassCastException error? [duplicate]
class Person {
void speakTo(Person other) { System.out.println("kudos"); }
void watch(SoccerPlayer other) { System.out.println("wow"); }
}
class Athlete extends Person {
...
0
votes
0
answers
12
views
ClassCastException - I just imported a project into eclipse and I'm getting this error when I run it
I just imported a project into eclipse and I'm getting this error when I run it.
This is the error log on the console
Exception in thread "main" java.lang.ClassCastException: class jdk....
0
votes
0
answers
50
views
I'm currently trying to do battleships with RMI and would like to transfer the playground to the other client, but it woudn't work
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class Design.Playground cannot be cast to class java.rmi.Remote (Design.Playground is in unnamed module of loader 'app'; ...
0
votes
0
answers
61
views
java.lang.ClassCastException: class com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to class
I'm trying to write a Java unit test for the below code
public class PrintnetRequestTranslator extends RequestTranslator<MutationOverviewDocRequest, RequestContent> {
public ...
0
votes
1
answer
70
views
collecting Stream results in ClassCastException
I'm experiencing a ClassCastException with the following piece of code.
var temp = set.stream().flatMap(Arrays::stream).toArray(Token[]::new);
I also tried collecting into a set, but I got the same ...
0
votes
2
answers
100
views
java.lang.ClassCastException : java.lang.String cannot be cast to java.lang.Long
I'm trying to create a feed management system. I have created a simple get and post request for the servlet. I'm able to store the data in the datastore successfully as milliseconds.
But when I ...
1
vote
0
answers
96
views
ClassCastException in HashSet.put()
In seemingly simple code - as far as it relates to the problem - such as this:
private final HashSet<ValueType> set = new HashSet<>();
...
void doIt(ByteBuffer b) {
set.add(new ValueType(...
1
vote
0
answers
62
views
Java ClassCastException while getting object from List
I ran into a strange case in my application. It's even more strange because it have been runing for few years so far and there wasn't any problem with this but recently we faced the error.
In very ...
0
votes
1
answer
156
views
Scala Getting java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Double
My query is like
val demo = spark.sql(s"select PERCENTILE_APPROX(weight,array(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)) from db.demo_input_data")
scala> demo.first.getList(0)
res0: java.util....
0
votes
0
answers
18
views
Why ResponseEntity<Resource> does't return pdf in spring [duplicate]
I'm trying to download a PDF from my local machine. Everything is fine, but an error occurs while returning the resource. Please give clarity about a classcast exception and the proper solution to ...
0
votes
1
answer
46
views
How can I cast from double to object?
I'm trying to cast the fourth equals trough cast between double and Figura class but i don't know how to resolve.
I'm trying to cast the fourth equal to trough cast between the double and the Figura ...
0
votes
1
answer
90
views
ClassCastException casting a class instance to its own class because it is in an "unnamed module" with gradel and tomcat
There are many similar issues, but none I could find have the class being cast to itself. We are using a dependency on the webp support from this project:
implementation "org.sejda.imageio:webp-...
1
vote
0
answers
35
views
Why order of serializing a lambda expression containing a cirular-self-reference matters and can throw a ClassCastException?
ClassCastException is thrown by java8 when a lambda expression which contains a cirular reference via its expression arguments to itself, is deserialized.
The exception only is thrown when the lambda ...
0
votes
0
answers
43
views
c# I have a very confusing InvalidCastException error
I'm having an error that says "invalid cast exception" whenever I try to open one specific form in a program i'm making. The code here takes data from text files to put it into a data grid ...
0
votes
0
answers
97
views
java.lang.ClassCastException: javax.sql.rowset.serial.SerialClob cannot be cast to oracle.sql.CLOB
Here, I am converting serialclob to clob
Clob requestClob = new javax.sql.rowset.serial.SerialClob(
Reqt.frameRequest().toCharArray());
Clob responseClob = new javax.sql.rowset.serial.SerialClob(
...
1
vote
1
answer
70
views
'ClassCastException class [B cannot be cast to class [C' when attempting to generate spock reports
When generating unit test reports using spock-reports, I'm getting a ClassCastException:
class [B cannot be cast to class [C ([B and [C are in module java.base of loader 'bootstrap')
I'm using Java ...
0
votes
1
answer
32
views
ClassCastException: org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl cannot be cast to org.hibernate.loader.plan.spi.Fetch
I can not define what is wrong with my code. Last time I used it and it wordked, but now when I am trying to read User, I get ClassCast execption: java.lang.ClassCastException: org.hibernate.loader....
0
votes
0
answers
243
views
"java.lang.IllegalArgumentException: java.lang.ClassCastException@4ce4fde9" when trying to clone the subclass of an abstract class using a copy const
Here is the complete cloning process:
void ghost(){
//accesses player hotbar to grab the in-hand object
int hotbarAccessIndex = game.keyManager.lastNumKey;
//variable toClone is the object grabbed ...
-1
votes
1
answer
36
views
Exception in thread "main" error during object casting [java.lang.ClassCastException] - How to fix casting issue?
I am writing a program which consists of several classes (2 superclasses and a couple subclasses for each). Within my driver file, I created two arrays: the first array contains objects from two ...
0
votes
0
answers
18
views
Getting ClassCastException While Using multi modules an d native methods in GWT Project
I am working on a GWT project .I have a base module where lets say class MyApp is present. Another module (moduleA) is importing the base module.In this we are exposing some methods as native methods ...
0
votes
1
answer
79
views
Using JS function returning dynamic in Kotlin JS within the default Promise constructor results in ClassCastException
I got this error when trying to transform gapi calls into Promises, but I suppose calls to other functions may result in the same issue. First, I added the library as a script in the page:
script(src =...
0
votes
0
answers
23
views
$Proxy92.<method-name> not avilable
During runtime my application is throwing
java.lang.ClassCastException: java.lang.String cannot cast to <CustomDTO>
It is not invoking the actual method but instead it is invoking a com.proxy.$...
0
votes
0
answers
10
views
Understading ClassCastException
public class CastingExcpetionEx1 {
public static void main(String[] args) {
final Object exception = new Exception(); // unchecked exceptions
final Exception data = (RuntimeException)...
2
votes
1
answer
1k
views
Kafka : ClassCastException: class org.apache.avro.generic.GenericData$Record cannot be cast to class
I have this exception in the consumer when trying to cast the record.value() into java object :
ClassCastException: class org.apache.avro.generic.GenericData$Record cannot be cast to class [...]....
1
vote
0
answers
22
views
java.lang.ClassCastException(Android-Studio)
I am getting this error in my app and my app crashes.
java.lang.ClassCastException: android.location.Location cannot be cast to com.example.locationtest.LocationData
LocationData class
package com....
0
votes
0
answers
27
views
ClassCastException:cannot cast HTTPClient4TransportSender to TransportSender in Axis2 [duplicate]
I have added axis2.xml in server and trying to load the configurationContext using java code.But during loading the configuration getting classCastException for class org.apache.axis2.transport.http....
1
vote
0
answers
62
views
ClassCastException when using wildcard in java
I got ClassCastException when running java code below:
public static void main(String[] args) {
String text = "{" +
"\"number\": 1" +
...
1
vote
3
answers
162
views
How to avoid catching OutOfMemoryError in java and how to resolve class java.lang.OutOfMemoryError cannot be cast to class java.lang.Exception issue
for (int i = 0; i <listOfProcesses.size(); i++) {
try {
Future<Boolean> futureResult = executorCompletionService.take();
boolean status = futureResult.get();
} catch (...
-1
votes
1
answer
856
views
java.lang.ClassCastException: myClass cannot be cast to class java.util.List
I have a class setup called MyClass that holds two lists:
public class MyClass {
List<String> list1;
List<Descriptor> list2;
public List<String> getList1() { return ...
1
vote
1
answer
210
views
Error when using ActionListener button click to hide a JFrame and reveal another
I'm trying to "open" a different JFrame window on button click (in this case, the dimensions button), like when going through a menu. I have my 2 windows, Main function and ActionListener as ...
0
votes
1
answer
143
views
Jetty 9.4.44 - Deployment Failure - ClassCastException
I'm trying to setup a Jetty 9.4.44 environment and running into a deployment failure for a vanilla app. The setup uses the stock Jetty and there's no customization. The app just has a welcome page and ...
4
votes
1
answer
217
views
Android tests using sharedViewModel fail with java.lang.ClassCastException androidx.lifecycle.SavedStateHandleController when upgrading Koin to 3.1.3
I'm currently using Koin version 3.1.0 and want to upgrade to the latest version (currently 3.1.4), But once I upgrade Koin to 3.1.3 are above I get the following exception when I run my tests:
class ...
0
votes
1
answer
44
views
Android: ClassCastException on PreferencesActivity onCreate when app is updated (NOT in first run)
I'm about to launch an update of my app, but facing a problem.
One of the preferences class has been changed from CheckBox to Switch and now users who previously installed the app are getting a crash ...
5
votes
3
answers
140
views
Why is a cast from Double to <T : Number> possible, but not from Double to Int?
In the following, I have a generic function fun <T : Number> sum(list : List<T>) : T with a type parameter T : Number.
In the function, I sum up the list's numbers as a sum : Double and ...
2
votes
1
answer
180
views
ClassCastException When Initialising Interface ViewModel Using by navGraphViewModels() [with Hilt]
I have a Fragment flow scoped with a navigation graph and want to scope each Fragment's ViewModel accordingly. However, I don't want each of the Fragments to have access to all methods and variables ...
0
votes
1
answer
51
views
REST api with only 1 object java
This code makes use of JSON-simple for connecting to an api:
try {
URL url = new URL("https://api.kanye.rest/");
HttpURLConnection conn = (HttpURLConnection) url....
2
votes
0
answers
1k
views
java.lang.ClassCastException : xxx is in unnamed module of loaderl; xxx in module java.xml of loader 'bootstrap'
I am developing an Eclipse RCP Application on my target platform. (*.target file)
I called org.eclipse.sphinx.emf.resource.ExtendedXMLLoadImpl to load an xml file(it is arxml file).
And there is a ...
0
votes
0
answers
14
views
how to resolve java.lang.ClassCastException: net.sf.json.JSONObject cannot be cast to net.sf.json.JSONObject [duplicate]
I am using json-lib-0.9.jar. in view.class i am getting inputstream from the request, setting into request and dorwarding request to Render.jsp, i am not able to understand how to fix this. could ...
0
votes
1
answer
94
views
ClassCastException in OptaPlanner due to a groupBy operation
I'm creating a school schedule generator and I'm getting an exception from one of my constraints which checks that all students have lunch breaks every day.
I'm using the constraint stream Java API. ...
0
votes
1
answer
89
views
management endpoints throwing GroovyCastException when served on different port
I have the following health management endpoints in my application.yml file
management:
endpoints:
health:
sensitive: false
web:
base-path: /
and I have an interceptor ...
-1
votes
1
answer
47
views
What does j.u.v. stand for in `java.lang.ClassCastException: j.u.v cannot be cast to kotlin.collections.MutableList` [duplicate]
I am seeing a bunch of ClassCastException crashes in my project and the stacktrace describing:
java.lang.ClassCastException: j.u.v cannot be cast to kotlin.collections.MutableList
I can't seem to ...
0
votes
0
answers
47
views
org.apache.cxf.interceptor.Interceptor Class cast exception
I'm trying to deploy a webapp (war) in a tomcat server. The webapp uses @Ininterceptor annotation which accepts org.apache.cxf.interceptor.Interceptor type classes.
Im getting 'com.xxx.xxx.MyClass ...
0
votes
1
answer
577
views
Getting spring boot Exception: java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class
I am getting java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class. Not able to understand root cause of this error and how to solve it.
This is my query code:
Query query3 = ...
-1
votes
1
answer
50
views
Java is NOT throwing ClassCastException for a non-parameterised List
I have a List that was initialised without any parameters. I added Map<String, Object> to that list.
Then I created a User object, and I know after typecasting the list to List<User> at ...
0
votes
2
answers
59
views
Hibernate: Passing a list of data to `SELECT IN ( )` clause generate errors
I am trying to generate a Hibernate Query. Below is my code
public List<Product> getProductsByIDList(List<Product> list, Session session) {
//Query query = session.createQuery(&...