Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:28:21+00:00 2026-05-31T10:28:21+00:00

I am trying to query the data store and cast it to a user

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:28:24+00:00Added an answer on May 31, 2026 at 10:28 am

    May I suggest:

    1.Delete the line

    import com.gwt.samples.shared.List;
    

    2.Instead of

    Query q=pm.newQuery(List.class);
    

    and

    res=(ArrayList<List>)q.execute(user_id); //error occurs here i guess
    

    use

    Query q=pm.newQuery(com.gwt.samples.shared.List.class);
    

    and

    res=(ArrayList<java.util.List>)q.execute(user_id);
    

    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 res is of data type ArrayList<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 res to get things to work.

    I have a standard method for querying. The query return is stored in a java.util.List. I then do

    java.util.List liResult = [My query];
    ArrayList alResult = new ArrayList(liResult);
    

    Ouside of my method, I cast my ArrayList to ArrayList<[Query data type]>.

    Any help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException:
I'm trying to store a Int64 variable to data column with bigint data type.
I am trying to send some data from a LINQ query in C# to
I'm trying to write a query that extracts and transforms data from a table
I am trying to export the following data in the query from ms sql
Trying to query a 'Favorites' model to get a list of items a user
I'm trying to query a MySQL database using an array but I'm having trouble!
I'm trying to query a DBF file using System.Data.Odbc.OdbcConnection. It works correctly when the
I'm trying to store data from a MySQL table into an PHP array variable.
Alright, so I'm trying to store data in Sqlite. So I'm trying to store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.