0

在这里,我尝试将所有 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 值和存储的方式不正确,请帮助我。

4

2 回答 2

2

将您的双精度值转换为字符串,然后存储到数组列表中。或者简单地制作双精度数组列表来存储纬度和经度的所有双精度值。

示例 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);
于 2013-10-10T12:03:19.580 回答
1

问题是将ParseObject存储valueObject. 因此,您正在尝试将 aDouble转换为 a String。通常,IDE 会为此发出警告。现在发生这种情况:

Object sneakyDouble = (Double)0.4d;
String s = (String)sneakyDouble;

你如何解决它?只需使用:

eventLatitudeList.add(greenmarkers.get("eventLatitude").toString());
eventLongitudeList.add(greenmarkers.get("eventLongitude").toString());
于 2013-10-10T12:16:21.600 回答