简体   繁体   中英

java.lang.Long cannot be cast to [Ljava.lang.Object;

List cc;

    cc=em.createNativeQuery("SELECT COUNT(Submission_Id) AS count FROM Submissiontb").getResultList();
            lst.clear();

    for (int i=0;i <cc.size();i++)
    {
    Object []oo=(Object[])cc.get(i);
    submission c=new submission();
  //  c.setCount(oo[0]+"");
    c.setCount(oo[0]+"");
    System.out.println(c);
    lst.add(c);

    }

in this code oobject cannot cast java.lang.Long cannot be cast to [Ljava.lang.Object;

The exception says (correctly) that you can't cast a single Long to an array of Object . It is not a legal typecast because a Long is not a subtype of Object[]

Cast it to Object .

(I cannot see why you are even trying to use an Object[] here. A SELECT COUNT... query will only ever return one value.)

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