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.

ClassCastException is the Java unchecked exception thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.

FAQ:

  1. Explanation of "ClassCastException" in Java
  2. What else can throw a ClassCastException in java?
1698 questions
20
votes
9 answers

java.lang.RuntimeException: Unable to instantiate activity in Flutter

Flutter newly created app gives error when using fire base. How should i fix this problem as it is asking flutter app main activity cannot be cast to android app activity. 04-05 21:16:07.570 27391-27391/? E/AndroidRuntime: FATAL EXCEPTION: main …
demitri kozlov
  • 247
  • 1
  • 3
  • 14
20
votes
4 answers

java.lang.String cannot be cast to [Ljava.lang.String;

I have the following and I get the error java.lang.String cannot be cast to [Ljava.lang.String; I have changed the Object[] to String[] because I faced the next error: java.lang.Object cannot be cast to [Ljava.lang.String; Any idea? private…
Giorgos
  • 637
  • 3
  • 13
  • 25
19
votes
1 answer

Class cast exception to same class on Android

I'm having a strange problem with ClassCastException on Android. One class cannot be casted to the same class: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.ClassCastException: com.example.model.BadeWrapper cannot be…
rwojcik
  • 1,030
  • 9
  • 18
18
votes
2 answers

hadoop MultipleInputs fails with ClassCastException

My hadoop version is 1.0.3,when I use multipleinputs, I got this error. java.lang.ClassCastException: org.apache.hadoop.mapreduce.lib.input.TaggedInputSplit cannot be cast to org.apache.hadoop.mapreduce.lib.input.FileSplit at…
tony marbo
  • 251
  • 1
  • 5
  • 13
17
votes
3 answers

Generics, arrays, and the ClassCastException

I think there must be something subtle going on here that I don't know about. Consider the following: public class Foo { private T[] a = (T[]) new Object[5]; public Foo() { // Add some elements to a } public T[] getA() { return…
ntownsend
  • 7,462
  • 9
  • 38
  • 35
17
votes
3 answers

java.lang.ClassCastException: android.os.BinderProxy cannot be cast to LocalBinder

I have a Service that I am trying to bind to my main Activity, but I am receiving a java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.walintukai.rubix.ConnectionService$LocalBinder. I have declared the service in my…
17
votes
1 answer

ArrayList cannot be cast to Parcelable

I get following Errors: Key com..BookStatus expected Parcelable but value was a ArrayList ClassCastException: ArrayList cannot be cast to Parcelable -> and therafter: Unable to start Activity - NullPointerException the ArrayList do have values of…
flyOWX
  • 215
  • 1
  • 2
  • 11
17
votes
3 answers

ClassCastException ViewGroup$LayoutParams cannot be cast to ViewPager$LayoutParams

My initial code line is inside the overridden method onGlobalLayout(): img.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 100)); ClassCastException occuring in the overridden method onGlobalLayout()- Error Log: 09-02 14:25:35.326:…
sjain
  • 23,126
  • 28
  • 107
  • 185
17
votes
3 answers

FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used

In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me ClassCastException saying FrameLayout can not cast to RelativeLayout. I don't have any…
16
votes
1 answer

How to fix 'class java.util.LinkedHashMap cannot be cast to class' when using Java 8 and Java 11

I'm working with a micro-service built using Java 11, this service has a dependency built in Java 8. Dependency has rest-clients in it and there is a method that does this: public ResponseEntity> getForList(String url,…
Alex Andrade
  • 342
  • 1
  • 3
  • 14
16
votes
2 answers

Why wrapping a generic method call with Option defers ClassCastException?

Lets say I have an array like this*: val foo: Any = 1 : Int Option(foo.asInstanceOf[String]) which fails for obvious reason: // java.lang.ClassCastException: java.lang.Integer cannot be cast to // java.lang.String // ... 48 elided Next lets…
zero323
  • 322,348
  • 103
  • 959
  • 935
16
votes
7 answers

ClassCastException vs. "cannot cast" compilation error

Studying for my OCA Java SE 7 Programmer I exam, so newbie question. I have an example question I do not understand. The following code compiles, but gives a ClassCastException at runtime: interface Roamable { } class Phone { } public class Tablet…
luukburger
  • 637
  • 6
  • 14
15
votes
7 answers

CXF - ClassCastException (SEIStub/ClientProxy)

I'm trying to build a client jar file to access a webservice. I'm including the jar in a servlet/war that makes the client webservice calls. I'm getting the following error: INFO: 2011 Apr 14 14:57:32,780 MDT [http-thread-pool-8181(4)] ERROR …
sdoca
  • 7,832
  • 23
  • 70
  • 127
15
votes
4 answers

Meaning of java.lang.ClassCastException: someClass incompatible with someClass

I was experiencing occasional exceptions in XPages application: java.lang.ClassCastException: someClass incompatible with someClass. Both mentioned classes are the same, it is class used as session bean. I was not able to google anything covering…
Frantisek Kossuth
  • 3,524
  • 2
  • 23
  • 42
15
votes
6 answers

How to convert ArrayList to String[] in java, Arraylist contains VO objects

Please help me to convert ArrayList to String[]. The ArrayList contains values of type Object(VO). For example, The problem is that I need to convert a country List to String Array, sort it and then put it in a list. However I am getting a…
user1000535
  • 957
  • 2
  • 8
  • 8