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
0
votes
5 answers

Java Generics Causing Class Cast Error

So I'm coding up a generic adjacency list and my code has no compile errors, but when I run my tests I get the same runtime error across the board: java.lang.ClassCastException: [[Ljava.lang.Object; cannot be cast to [[Lds.Graph.Edge; at…
Ethan
  • 1,206
  • 3
  • 21
  • 39
0
votes
2 answers

ClassCastException in BookingApp

I'm getting a ClassCastException at: RVBooking rvbooking = (RVBooking) bookingList.get(iweight); I want to store the user's weightvehicle input and invoke the recordWeight() method. Sorry if i am not explaining this clearly. Thanks in advance.…
Ken
  • 45
  • 1
  • 5
0
votes
1 answer

Init parent class with a Child contstructor in Java, theory

I've just tested this code. Main. public class Main { /** * @param args */ public static void main(String[] args) { Parent parent = new Child(12, "Lorem", 12); if (parent instanceof Parent) { …
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
0
votes
1 answer

Saving file with casting error

java.lang.ClassCastException: infrastructure cannot be cast to terrain at p2_assign_version2.main(p2_assign_version2.java:98) This is the error that is constantly being printed when I try to build my file. Due to this error i m not able to print…
0
votes
1 answer

ClassCastException ObjectStreamClass cannot be cast to java.lang.String when deserializing

I am trying to serialize, send and receive an instance of the below class ( ServerGameDataObject object = new ServerGameDataObject() ) public class ServerGameDataObject implements Serializable { private static final long serialVersionUID =…
0
votes
1 answer

ClassCastException when persisting enum via Hibernate

I've now wasted several hours trying to get this to work, but Hibernate still keeps me wondering what's going on there inside. Here's what I want to do: Simply persist a List of enums via @Enumerated which looks like…
Zhedar
  • 3,480
  • 1
  • 21
  • 44
0
votes
1 answer

java.lang.ClassCastException: android.widget.TextView ERROR

I am getting a ClassCastException error. I don't know why. Tried to clean my project, but nothing happened. Thanks in advance! logcat: 04-30 18:03:44.122: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 04-30…
0
votes
0 answers

Android removing TitleBar for Activity causes ClassCastException. Why?

I'm getting a ClassCastException on the following line: content = ((LinearLayout) findViewById(android.R.id.content).getParent()); This is only when I set the theme of the Activity/App as android:Theme.NoTitleBar Same problem with Fullscreen…
JabezMMM
  • 483
  • 5
  • 8
0
votes
2 answers

ClassCastException on SimpleAdapter in Android

I am trying to display a list of alarms in my Android application but I am getting an Exception. How can I resolve this? This is where I am trying I initialise the adapter: List list; Database db = new…
Johnathan Au
  • 5,244
  • 18
  • 70
  • 128
0
votes
1 answer

Truncated Java object when passing through JAX-WS WebService

I am currently working on a project that uses JAX-WS webservices in Java. The global topic is this : the user creates locally an object, let's say an Agent. He calls a first webservice and passes its Agent to the webservice. The webservice treats…
David Ferrand
  • 5,357
  • 1
  • 33
  • 43
0
votes
1 answer

java.lang.ClassCastException: java.util.ArrayList cannot be cast to ....CrExcessMaster

My code is private List find(String queryString) { final Query query = getSession().createQuery(queryString.intern()); List resultSet = query.list(); return resultSet; } @SuppressWarnings("rawtypes") public List < CrExcessMaster >…
user2265200
  • 39
  • 3
  • 8
0
votes
1 answer

ClassCastException - related to JSON parsing, came out of nowhere

My app was seemingly running fine for a while now, when all of a sudden I started getting a ClassCastException when running a portion of the app that runs a query via REST API. I have no idea where it came from or why it cropped up now, as it was…
user2163853
  • 907
  • 4
  • 14
  • 24
0
votes
3 answers

ClassCastException error, dont know why it occurs

I m working with BaseAdapter class and i get an ClassCastException error in getView method when i try to cast my viewHolder class. Here is my code: public View getView(int position, View convertView, ViewGroup parent){ // TODO…
Ainius
  • 336
  • 3
  • 11
0
votes
4 answers

Finding median of variable type of arguments

I have a method which takes variable number and types of arguments in the form of Object. I want to calculate the median of only the numbers in those arguments. I used Lists to insert the elements(numbers) and then Collections to sort the List. I…
Parijat Bose
  • 380
  • 1
  • 6
  • 22
0
votes
1 answer

NetBeans Maven: ClassCastException - RestEasy vs Jersey

As my title says, I believe the issue is with classloading, and the fact that my application is trying to cast a jersey-core class to resteasy. Below is the code that triggers it, as well as the error: java.lang.LinkageError: ClassCastException:…
Metal Wing
  • 1,065
  • 2
  • 17
  • 40
1 2 3
99
100