Cast exception while setting name

后端 未结 2 396
情话喂你
情话喂你 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:25

    Try use it

    customer[0].toString()
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题