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?
1609 questions
10
votes
2 answers

No compiler error about incompatible casts

Sorry if this was already explained, but i didn't find similar threads anywhere in web. Today I opened one project class in IDE and saw an error (red underline), though project was compiled successfully. So, the code is: public interface…
AdamSkywalker
  • 10,723
  • 2
  • 33
  • 71
10
votes
3 answers

Why does it compile when casting to an unrelated interface?

interface Printable {} class BlackInk {} public class Main { public static void main(String args[]) { Printable printable = null; BlackInk blackInk = new BlackInk(); printable = (Printable)blackInk; } } If the…
korshyadoo
  • 337
  • 7
  • 18
10
votes
3 answers

Reflections IllegalArgumentException causes

UPDATE - To make the question clearer. What is the possible cause of getting a ClassCastException while calling a method via reflections? I got the following stacktrace as a part of my application while trying to invoke a method via…
Aditya
  • 2,008
  • 3
  • 18
  • 32
10
votes
3 answers

ClassCastException LinearLayout LayoutParams

I got an Actionbar and some Fragments. The Problem is my Homescreen. There is an overview Fragment on the left side and a detail Fragment on the right side. My TabListener is Dynamic so i want to set the weight of my Layout programatically. Whenever…
9
votes
2 answers

Changed order in main.xml, now I get ClassCastException

Using eclipse and the Android SDK, I managed a simple test app with a Button and a ProgressBar. All runs fine, except I did't want the ProgressBar to move the Button, when the ProgressBar was made visible, so just for testing I changed the order…
OppfinnarJocke
  • 983
  • 2
  • 8
  • 20
9
votes
6 answers

ClassCastException when casting looked-up EJB view in AS7

I have am deploying 2 EARs onto JBoss AS 7.1.0.Alpha1-SNAPSHOT (post 7.0.1.Final version). Both deploy fine. I have an EJB Singleton class packaged within a JAR, within one of the EARs: @Startup @Singleton // one of @Local(Store.class),…
Ben Kirby
  • 892
  • 2
  • 11
  • 29
9
votes
2 answers

java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat

Switching from LinearLayout to ConstraintLayout throwing this error java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat …
Santanu Sur
  • 8,836
  • 7
  • 24
  • 43
9
votes
2 answers

Hibernate -> ArrayList cannot be cast to Set

I have a Java EE application and I use Hibernate. The domain objects, I changed the List / ArrayList to Set / HashSet, because it is better to use Sets. But in my Dao implementation I run into a problem: public Set getAllPersons() { …
Tim
  • 12,894
  • 35
  • 105
  • 158
9
votes
1 answer

ClassCastException: interface akka.actor.Scheduler is not assignable from class akka.actor.LightArrayRevolverScheduler

I am trying to run something I have been successfully running under a variety of conditions for months. I am using akka-actor_2.11 2.3.4 with scala-library 2.11.7 from a Java application running Java 7. Like I said, the same code has worked for…
mephicide
  • 314
  • 2
  • 11
9
votes
4 answers

Primefaces datatable date range filter with filterFunction

I use filterFunction method of datatable on primefaces 5.0. I want to filter birthday by date range on column header. On browser console I receive this error:
zekifh
  • 169
  • 1
  • 2
  • 9
9
votes
2 answers

ClassCastException when trying to do readParcelable on custom object array

I'm trying to implement Parcelable instead of Serializble as it's supposed to be more efficient. From my MainActivity I want to pass a Message object to another activity, my class Message contains other classes. If I get past this one error I'm sure…
Phoebe
  • 129
  • 2
  • 8
9
votes
3 answers

Fatal Exception: String can't be cast to Spannable

My app works greatly with the exception of a few devices. On one such device, I get a FATAL EXCEPTION in one of my activities. The error is java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spannable ... ... at…
user1857437
  • 259
  • 3
  • 13
9
votes
7 answers

Class extending Application throws ClassNotFoundException

I have a class that extends the application class and sometimes in my developer console I see an error saying ClassNotFoundException java.lang.RuntimeException: Unable to instantiate application ecm2.android.ActiveStore:…
tyczj
  • 66,691
  • 50
  • 172
  • 271
9
votes
6 answers

How to cast two instance of the same loaded different classloader?

I have two different webapps, and each load the same class A with different classloader. When I put one instance in the session and then get it from the other webapp, a ClassCastException is thrown. For example, in webapp A, I store a in the…
xiaolg2008
  • 91
  • 1
  • 4
8
votes
1 answer

Cannot cast eclipse project to IJavaProject

I have the following code IJavaProject targetProject = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IProject project : root.getProjects()) { if (project.getName().equals(projName)) { try…
Joeblackdev
  • 6,967
  • 23
  • 64
  • 103