Cast exception while setting name

后端 未结 2 397
情话喂你
情话喂你 2021-01-25 23:00

I am getting a cast exception while setting the name.

        Object[] customers= customerRepository.getCustomerName(Id);     
        Customer row = new Custom         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 23:26

    So no one bothered to read the exception message?

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

    The leading [ indicates that the class is an array class.

    What you're getting above is:

    row.setName(((String) customers)[0]+" "+((String) customers)[1]);
    

    Cast has precedence over array indexing.

提交回复
热议问题