简体   繁体   中英

How to populate a List<Object[]>[] with a Vector?

I'd like to populate an array with Vector s. The variable is declared as below:

private List<Object[]>[] group; 

However, when I populate it with a Vector , below exception is thrown:

java.lang.ArrayStoreException: java.util.Vector
    at presentationtier.GraphMB.createTables(GraphMB.java:68)
    at presentationtier.GraphMB.init(GraphMB.java:48)

How is this caused and how can I solve it?

public List<Object[]> getInv_AccountingError(String action){
        EntityManagerFactory emf = null;
        EntityManager em = null;
        List<Object[]> list = new ArrayList<Object[]>();
        try{
            emf = Persistence.createEntityManagerFactory("Test");
            em = emf.createEntityManager();

            Query query = em.createNativeQuery("select k.* from "+action+" k");
            list = query.getResultList();   

I am getting a List of object array from the db and i loop around this method like call it n times to get a array of list then why vector is comming?

The error ( Throws ArrayStoreException ) occurs in the following situation in your case.

If a component of this list is not of a runtime type that can be stored in the specified vector.

Your group variable is of a rather complicated type. Each element of group has to be of type List<Object[]> . The ArrayStoreException occurs when you try to put the wrong type of element into an array. So there are only two possibilities here:

  1. You're trying to insert into group an element that isn't a List that contains an array of Object ; or
  2. You're trying to populate one of those arrays of Object , but you declared it as something more specific than Object[] and now you're trying to put the wrong type into it.

Based on your comments, you probably need to define group like this:

private Object[][] group;

This makes an array of Object arrays. So when you get a value of type Object[] , you'll be able to store that as an element of group :

Object[] anElement = // well, wherever they come from
group[i] = anElement;

In your original version of the post you seem to have two variables named 'var'.

First one in the for-each tag that has integer-indexes and another for the data-table tag.

My guess is that when you attempted to access the 'columns' element with the value of the 'var' it was not the one with the integer value but the one with the array!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM