1. Are you ready for the Galaxy S20? Here is everything we know so far!

In convertible Types: Cannot cast 'java.lang.Object[]' to 'java.lang.Double'

Discussion in 'Android Development' started by maddie_jones, Apr 1, 2016.

  1. maddie_jones

    maddie_jones Newbie
    Thread Starter

    I am trying to retrieve data from foursqaure API, however, when I try to retireve the places rating I am getting the error message which says In convertible Types: Cannot cast 'java.lang.Object[]' to 'java.lang.Double' . Please help.

    I am getting the error message for this line below:
    Code (Text):
    1.  
    2.   this.itemrating = (Double)temprating.toArray();
    3.  
    Please can you please and sort out the issue I am currently facing.
     


    #1 maddie_jones, Apr 1, 2016
    Last edited: Apr 1, 2016
  2. Best Answer:
    Post #2 by Deleted User, Apr 1, 2016 (1 points)
  3. Deleted User

    Deleted User Guest

    You've declared itemrating as a Double, not an array of Double. It should be

    Code (Text):
    1.  
    2. private final Double[] itemrating;
    3.  
    and your other line should be

    Code (Text):
    1.  
    2. this.itemrating = (Double[])temprating.toArray();
    3.  
     
    maddie_jones likes this.
  4. maddie_jones

    maddie_jones Newbie
    Thread Starter

    Thank you This has helped me, just a stupid mistake from me.
     
    Deleted User likes this.
  5. Deleted User

    Deleted User Guest

    btw you don't actually need the explicit cast statement, as the compiler is clever enough to figure out that toArray() returns a Double[]. So this should work

    Code (Text):
    1.  
    2. this.itemrating = temprating.toArray()
    3.  
     
Loading...

Share This Page

Loading...