0

So far I found some answers here but I'll get everytime Errors that I cant convert from Object to String and so on for example I used now this idea:

I have that following List of Objects which is mapped with my Database: List<OPBList> list123

now i tried this:

    String[] arr = list123.toArray(new String[] {});
    return arr;

heres m OPBList class:

     @Entity
     @Table(name = "T_OPB_LIST")
     @XmlRootElement
     @NamedQueries({
      @NamedQuery(name = "AllOPBLists", query = "Select a from OPBList a")
      })
     public class OPBList implements Serializable {
      private static final long serialVersionUID = 1L;
   @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic
@XmlAttribute
@XmlID
private Long id;

@Basic
private String company;

@Basic
private String country;

with some getter and setter methodes

and I get this Error :

HTTP Status 500 - java.lang.ArrayStoreException

Any Ideas how I can do that?

9
  • please, post OPBList class code. Commented Jun 1, 2016 at 12:27
  • @vishalgajera its just too long, plus too complicated but I try to explain it Commented Jun 1, 2016 at 12:33
  • You have things in the list that aren't Strings. Commented Jun 1, 2016 at 12:33
  • @immibis yes and I want to convert them to strings Commented Jun 1, 2016 at 12:44
  • Convert List to String[] in Java Commented Jun 1, 2016 at 12:47

1 Answer 1

0

If your List contains OPBList objects, you cannot put them into an Array that contains String objects.

In your case you should do

OPBList[] arr = list123.toArray(new OPBList[] {});

according to the documentation

public class ArrayStoreException extends RuntimeException Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your interest, the point is I want to compare those "objects" with some strings .....
I see your Object has 3 properties: id, company, country. What is it that you want to compare? And then what do you want your method to return?
well there are 2 more properties, the point is theres one property thats called "CEO" and I write a void method and give that method some paremeter, which company,which country and so an, and then I want to write a logic which compares those paremeters of that method with my properties, because I want then a return which give me back who is the CEO of that company (this is just an example)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.