For some reason, this code is throwing a ClassCastException, telling me that I cannot cast a Double to a Float. The exception emanates from the first line of code below. mapData.speeds is an ArrayList<Float>.
Where is the Double?
float spd = mapData.speeds.get(focusPointIndex);
spd = (spd * 3600/1609.34);
Here is the complete stack trace:
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)
--edit--
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.
private <T> ArrayList<T> JSONArrayToList(JSONArray jsonArr){
ArrayList<T> arrList = new ArrayList<T>();
for(int i = 0; i<jsonArr.length(); i++){
try {
arrList.add((T)jsonArr.get(i));
} catch (JSONException e){e.printStackTrace();}
}
return arrList;
}
spddeclared to be afloator aFloat? And are you absolutely sure that the error is not from the second line?