这里我尝试将所有eventLatitude,eventLongitude存储在arrayLists中:
我到目前为止尝试过:
`ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"GreenMarkers");
query.orderByDescending("_created_at");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
for (ParseObject greenmarkers : ob) {
eventLatitudeList.add((String) greenmarkers.get("eventLatitude"));
eventLongitudeList.add((String) greenmarkers.get("eventLongitude"));
}`
但是在arraylist中存储值时无法获得错误 日志
10-10 17:22:25.021: E/AndroidRuntime(21178): FATAL EXCEPTION: main
10-10 17:22:25.021: E/AndroidRuntime(21178): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tukutane/com.tukutane.StartActivity}: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread.access$700(ActivityThread.java:143)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.os.Looper.loop(Looper.java:137)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread.main(ActivityThread.java:4960)
10-10 17:22:25.021: E/AndroidRuntime(21178): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 17:22:25.021: E/AndroidRuntime(21178): at java.lang.reflect.Method.invoke(Method.java:511)
10-10 17:22:25.021: E/AndroidRuntime(21178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
10-10 17:22:25.021: E/AndroidRuntime(21178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
10-10 17:22:25.021: E/AndroidRuntime(21178): at dalvik.system.NativeStart.main(Native Method)
10-10 17:22:25.021: E/AndroidRuntime(21178): Caused by: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
10-10 17:22:25.021: E/AndroidRuntime(21178): at com.tukutane.StartActivity.onCreate(StartActivity.java:131)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.Activity.performCreate(Activity.java:5203)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
10-10 17:22:25.021: E/AndroidRuntime(21178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
我认为我获取所有eventLatitude,eventLongitude值和存储的方式不正确,请帮帮我。
答案 0 :(得分:2)
将double值转换为String,然后存储到arraylist中。或者简单地使用两个arraylist来存储纬度和经度的所有双倍值。
示例1:
String lat = String.valueOf(doublevalue);
ArrayList<String> latlist = new ArrayList<String>();
latlist.add(lat);
示例2:
ArrayList<double> latlist = new ArrayList<double>();
latlist.add(doublevalue);
答案 1 :(得分:1)
问题在于ParseObject
将value
存储为Object
。因此,您尝试将Double
投射到String
。通常,IDE会为此发出警告。现在发生这种情况:
Object sneakyDouble = (Double)0.4d;
String s = (String)sneakyDouble;
你是如何解决的?只需使用:
eventLatitudeList.add(greenmarkers.get("eventLatitude").toString());
eventLongitudeList.add(greenmarkers.get("eventLongitude").toString());