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?

TechAffinate
  • 61
  • 1
  • 14

1 Answers1

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.

DavideS
  • 41
  • 5
  • thanks for your interest, the point is I want to compare those "objects" with some strings ..... – TechAffinate Jun 01 '16 at 12:48
  • 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? – DavideS Jun 01 '16 at 12:58
  • 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) – TechAffinate Jun 01 '16 at 13:03