1. Download our Official Android App: Forums for Android!

Apps 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
    Rank:
    None
    Points:
    16
    Posts:
    19
    Joined:
    Mar 17, 2016

    Mar 17, 2016
    19
    1
    16
    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.
     

    Advertisement

    #1 maddie_jones, Apr 1, 2016
    Last edited: Apr 1, 2016
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,445
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,445
    10,729
    1,988
    Male
    Software developer
    South West of England
    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.
  3. maddie_jones

    maddie_jones Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    19
    Joined:
    Mar 17, 2016

    Mar 17, 2016
    19
    1
    16
    Thank you This has helped me, just a stupid mistake from me.
     
    LV426 likes this.
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,445
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,445
    10,729
    1,988
    Male
    Software developer
    South West of England
    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.  
     

Share This Page

Loading...