Note that there are some explanatory texts on larger screens.

plurals
  1. POClassCastException Double to Float
    text
    copied!<p>For some reason, this code is throwing a <code>ClassCastException</code>, telling me that I cannot cast a Double to a Float. The exception emanates from the first line of code below. <code>mapData.speeds</code> is an <code>ArrayList&lt;Float&gt;</code>. Where is the Double?</p> <pre><code>float spd = mapData.speeds.get(focusPointIndex); spd = (spd * 3600/1609.34); </code></pre> <p>Here is the complete stack trace:</p> <pre><code>03-31 01:00:51.008: E/AndroidRuntime(17778): FATAL EXCEPTION: main 03-31 01:00:51.008: E/AndroidRuntime(17778): java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Float 03-31 01:00:51.008: E/AndroidRuntime(17778): at net.taptools.android.trailtracker.ResultsMapViewingFragment$4.onMapLongClick(ResultsMapViewingFragment.java:224) 03-31 01:00:51.008: E/AndroidRuntime(17778): at com.google.android.gms.maps.GoogleMap$5.onMapLongClick(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at com.google.android.gms.internal.k$a.onTransact(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at android.os.Binder.transact(Binder.java:326) 03-31 01:00:51.008: E/AndroidRuntime(17778): at com.google.android.gms.maps.internal.IOnMapLongClickListener$Stub$Proxy.onMapLongClick(IOnMapLongClickListener.java:93) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.i.s.a(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.y.v.d(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.y.bf.onLongPress(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.d.v.onLongPress(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.d.h.c(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.d.h.c(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at maps.d.j.handleMessage(Unknown Source) 03-31 01:00:51.008: E/AndroidRuntime(17778): at android.os.Handler.dispatchMessage(Handler.java:99) 03-31 01:00:51.008: E/AndroidRuntime(17778): at android.os.Looper.loop(Looper.java:137) 03-31 01:00:51.008: E/AndroidRuntime(17778): at android.app.ActivityThread.main(ActivityThread.java:5059) 03-31 01:00:51.008: E/AndroidRuntime(17778): at java.lang.reflect.Method.invokeNative(Native Method) 03-31 01:00:51.008: E/AndroidRuntime(17778): at java.lang.reflect.Method.invoke(Method.java:511) 03-31 01:00:51.008: E/AndroidRuntime(17778): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792) 03-31 01:00:51.008: E/AndroidRuntime(17778): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 03-31 01:00:51.008: E/AndroidRuntime(17778): at dalvik.system.NativeStart.main(Native Method) </code></pre> <h1>--edit--</h1> <p>I think I have found what has caused the error, but still do not know why it is occurring, or how to fix it. I am parsing the mapData Object out of JSON, and because it contains many ArrayLists of various types, I created a method that will parse a JSONArray into and ArrayList of a designated type. Here is the method.</p> <pre><code>private &lt;T&gt; ArrayList&lt;T&gt; JSONArrayToList(JSONArray jsonArr){ ArrayList&lt;T&gt; arrList = new ArrayList&lt;T&gt;(); for(int i = 0; i&lt;jsonArr.length(); i++){ try { arrList.add((T)jsonArr.get(i)); } catch (JSONException e){e.printStackTrace();} } return arrList; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload