I am trying to query the data store and cast it to a user defined object type. But, i am getting an class cast error. Please look into the code
import com.gwt.samples.shared.List;
public ArrayList<String> viewLists(String user_id) {
PersistenceManager pm = PMF.get().getPersistenceManager();
ArrayList<String> res;
String[] ret;
Query q=pm.newQuery(List.class);
q.setFilter("owner_id == useridparam");
q.declareParameters("String useridparam");
try
{
res=(ArrayList<List>)q.execute(user_id); //error occurs here i guess
}
finally
{
q.closeAll();
}
return res;
}
The problem occurs because query.execute returns an Object and it cannot be casted to the type ArrayList . But, i am following this example from here
Please help
May I suggest:
1.Delete the line
2.Instead of
and
use
and
When you say “error occurs here i guess”, I presume that you can find out definitely by examining the relevant exception stack trace or log entry.
Also, I have just seen that your data member
resis of data typeArrayList<String>, whereas your query will return (incorporating my code changes above)java.util.List<com.gwt.samples.shared.List>.You will need to change the data type of either your query or
resto get things to work.I have a standard method for querying. The query return is stored in a
java.util.List. I then doOuside of my method, I cast my
ArrayListtoArrayList<[Query data type]>.Any help?