Hi there,

I am trying to get a data from a database using a query and populate it into a list view.
Instead of getting a string value, I am getting "[Ljava.lang.Object;@64bba873". I have tried to cast it, but it did not work

query1 = em.createQuery("Select e.name, y.surname from REQUEST e ,REQUEST y");
        List<String> list = query1.getResultList();

        record1.getItems().addAll(list);

record1 is my listview,

Could anyone help me to solve that out??

Many Thanks

Recommended Answers

All 5 Replies

What is 'query', what is 'em', what does 'getResultList()' return?

This code is way to vague to be clear.

Have you debugged over your code and checked the contents of list?

"[Ljava.lang.Object;@64bba873"

Is the result of your list view calling toString()on your data to convert it to a String for display. That output is the default toString() that every class inherits form Object - it just shows its class and hash.

You need to make your code more explicit as to how you want that list to be displayed, buthe fragment you posted doesn't have enough info for us to understand what the relevant variables and classes are in your code

Looking further at your code fragment, can I guess that you are using JavaFX?

If that's the case then the addAll method is for an ObservableList that you got from a JavaFX ListView's getItems() method. In that case you need to review the method documentation. It takes a var-arg number of items, which may also be an array, but is not a kind of List. You pass a single parameter, so that is added as a single object. Your listview now contains one entry - an instance of List, whose toString() method gives you the result you saw.

Rather confusingly, if this is right then ObservableList seems to conflict with Collection's addAll method that does what you want (adds the elements in a Collection) - maybe it's use of var-args allows it to capture calls that you would expect to use the inherited method from Collection?

@James:

Is the result of your list view calling toString()on your data to convert it to a String for display.

Indeed it does seem to be this. I wanted to post this earlier, but then I saw the type of elements in the list is <String>, so my guess is rather that he tries to print the List instead of its contents.

Anyway, I have no idea where it goes wrong, whether it is in a print statement, or the getResultList returns a list of Strings (obtained by Object's toString() implementation)

Yeah.
The "L" in the toString seems to imply some kind of list, but Lists in general use Collection's toString that gives a concatenation of all the lement's individual toStrings
Android Java also has a ListView class, but most of what I said would apply to that as well. We just don't have enough info to progress here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.