Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
The program firstly load the data from sql to vector. Then it will store the all the vector element to array.

When I compile, I get these errors. What's wrong here?
Java
java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
    at java.util.Vector.copyInto(Vector.java:192)
    at api.Case.ComparePre(Case.java:225)
    at api.Case.CompareType(Case.java:157)


What I have tried:

Java
public void ComparePre(Double[] value, Double[] array4,int[] array) throws Exception {
            // TODO Auto-generated method stub
 
            String sql="Select Pre1,Pre2,Pre3,Pre4,Pre5 from preferences ";
            DatabaseConnection db = new DatabaseConnection();
            Connection  conn =db.getConnection();
            PreparedStatement  ps = conn.prepareStatement(sql);
            Double[] b=new Double[4];
            Vector t =new Vector();
            ResultSet rs = ps.executeQuery();
            while (rs.next()) 
            {  
            Vector r =new Vector(); 
            r.add(rs.getInt("Pre1"));
            r.add(rs.getInt("Pre2"));
            r.add(rs.getInt("Pre3"));
            r.add(rs.getInt("Pre4"));
            r.add(rs.getInt("Pre5"));
            t.addAll(r);
            t.copyInto(b);
            }
       //    CountMatching(value,array4,array,b);
 
            ps.close();
            rs.close();
            conn.close();
        }
Posted
Updated 22-Dec-17 22:00pm
v3

1 solution

You aren't getting a compilation error, you're actually getting a runtime exception.
Looking up the ArrayStoreException in the Java documentation[^] you might find that you are trying to fill an array of doubles with integers (and you cannot do that).
 
Share this answer
 
Comments
wseng 23-Aug-15 13:07pm    
Thanks
CPallini 23-Aug-15 13:11pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900