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 6840557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:51:31+00:00 2026-05-26T23:51:31+00:00

What is wrong with below code ? List<Object[]> currencies = null; List<String> currencyList =

  • 0

What is wrong with below code ?

List<Object[]> currencies = null;
List<String> currencyList = new ArrayList<String>();

//code to fetch currency
String currencySql = "select C.Currency from Currency C";
Query currencyQuery = this.em.createQuery(currencySql);

currencies = currencyQuery.getResultList();

for (Object[] currency : currencies) {    //getting runtime error here
   for (int i = 0; i < currency.length; i++) {
            currencyList.add(currency[i].toString());
        }
    }

Getting runtime error in first line of for loop as:
java.lang.ClassCastException: java.lang.String incompatible with [Ljava.lang.Object;

The code compiles alright.

What is the issue ?

  • 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-26T23:51:32+00:00Added an answer on May 26, 2026 at 11:51 pm

    I’m not sure why you are thinking that the Query would return a list of Object arrays.

    The query will most likely return a list of Strings (unless the Currency entity contains a Currency object, in which case I’d revisit the data design), so operating under the assumption that this is a scalar query, your code can be simplified to:

    String currencySql = "select C.Currency from Currency C";
    Query currencyQuery = this.em.createQuery(currencySql);
    
    List<String> currencyList = (List<String>) currencyQuery.getResultList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats wrong in below JSON Object definition I am trying to create a new
My code below won't compile. What am i doing wrong? I'm basically trying to
I have the below code which is suppose to show a list of contact
I have written such the code below that ; I have an array list
I am using C# code and Tridion(CMS) classes to fetch data from Tridion, below
I have that error in the code below. What's wrong ? I have no
I have an object with a string-typed parameter called ' baan_cat_fam_code '. The code
May I know what's wrong with my code below.. 'cause it doesn't show the
What am i doing wrong in the below regular expression matching >>> import re
I wonder if there is something wrong with the copy constructor function below? class

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.