Results 1 to 6 of 6
Thread: Object casting
- 08-20-2009, 03:25 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
Object casting
I have a list consisting of 2 objects, each object contains an Object(Type JobRunStat), Long, Long and String parameters
So, I'm doing this:
And I get:Java Code:List returnJobs = selectQuery.getResultList(); for(int i = 0; i < returnJobs.size(); i++){ ReturnedObject o = (ReturnedObject) returnJobs.get(i);
[java] 15:33:02,453 ERROR [STDERR] java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to service.impl.JobRunServiceImpl$ReturnedObject
This is my ReturnedObject class:
with appropriate getters and setters for each field. Solutions?:)Java Code:private class ReturnedObject{ public JobRunStat jobRunStat = null; public Long contractId = new Long(0); public Long packageId = new Long(0); public String jobName = ""; public ReturnedObject(){ } public ReturnedObject(JobRunStat jobRunStat, Long contractId, Long packageId, String jobName){ this.jobRunStat = jobRunStat; this.contractId = contractId; this.packageId = packageId; this.jobName = jobName; }
-
Out of curiosity, if you run this before your exception occurs:
what is displayed? In other words, what objects is your list holding? They may not be what you think they are.Java Code:List returnJobs = selectQuery.getResultList(); System.out.println (returnJobs.get(0).getClass().getName());
- 08-20-2009, 04:14 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
[java] 16:27:19,015 INFO [STDOUT] [Ljava.lang.Object;
- 08-20-2009, 04:20 PM #4
Ping the code related to selectQuery object
Ramya:cool:
-
So it's most definitely not a List of ReturnedObjects.
- 08-20-2009, 05:43 PM #6
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
We need to see the getResultList() method. It appears that your list does not contain ReturnedObjects, so we need to see how the list is created.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
Similar Threads
-
Casting
By zzpprk in forum Advanced JavaReplies: 13Last Post: 08-13-2009, 07:59 PM -
What does casting mean?
By sev51 in forum New To JavaReplies: 3Last Post: 01-27-2009, 04:31 PM -
casting help
By soc86 in forum New To JavaReplies: 4Last Post: 01-13-2009, 11:07 PM -
Object to Int casting
By nn12 in forum New To JavaReplies: 4Last Post: 12-06-2008, 10:58 PM -
Casting
By leebee in forum New To JavaReplies: 5Last Post: 08-10-2007, 12:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks