aspose file tools*
The moose likes Beginning Java and the fly likes How to retrieve particular object from criteria list, I do not want object array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to retrieve particular object from criteria list, I do not want object array" Watch "How to retrieve particular object from criteria list, I do not want object array" New topic
Author

How to retrieve particular object from criteria list, I do not want object array

Bhupendra Dubey
Greenhorn

Joined: May 10, 2011
Posts: 6
I am getting exception
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.dto.AppDTO2
at com.action.AppService.main(AppService.java:121)
-----------------------------
code:
List li=criteria.list();
for(Iterator it = li.iterator();it.hasNext();)
{
AppDTO2 appDTO2 =
(AppDTO2) it.next();
System.out.println("ID: " + appDTO2.getCATEGORY());
System.out.println(" Name: " );

}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
. . . and the iterator is finding an Object[] type object. You are telling it that is a com.dto.AppDTO2 object, and it isn't. Hence the Exception.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retrieve particular object from criteria list, I do not want object array