无法将String转换为Integer

时间:2015-09-01 06:56:20

标签: java android

我知道之前已经问过这个问题了......我是Java的新手,也是Android的新手。

我的一位开发应用的朋友正在使用MPAndroidChartLibrary。

代码在本地服务器上正常工作。不是来自PUBLIC服务器。

这是代码

 private List<BarDataSet> getDataSet() {
    List<BarDataSet> dataSets;
    List<BarEntry> resolvedBarEntries = new ArrayList<BarEntry>();
    List<Integer> listKey = Lists.newArrayList(resolveSerMap.keySet());
    Collections.sort(listKey);
    for (Integer key : listKey) {
        BarEntry resolvedBar = new BarEntry(resolveSerMap.get(key), key);
        resolvedBarEntries.add(resolvedBar);
    }
    List<BarEntry> closedBarEntries = new ArrayList<BarEntry>();
    for (Integer key : listKey) {
        BarEntry closedBar = new BarEntry(closeSerMap.get(key), key);
        closedBarEntries.add(closedBar);
    }
    BarDataSet barDataSet1 = new BarDataSet(resolvedBarEntries,
            getResources().getString(R.string.Resolved));
    //barDataSet1.setColors(ColorTemplate.PASTEL_COLORS);

    BarDataSet barDataSet2 = new BarDataSet(closedBarEntries,
            getResources().getString(R.string.Closed));
    //barDataSet2.setColors(ColorTemplate.JOYFUL_COLORS);
    dataSets = new ArrayList<BarDataSet>();
    dataSets.add(barDataSet1);
    dataSets.add(barDataSet2);
    return dataSets;
}

这总是以例外结束  java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at com.example.user.getDataSet(Unknown Source) at com.example.user.promiseMethod(Unknown Source) at com.gaurage.util.RestUtil$3.onSuccess(Unknown Source) at com.a.a.a.h.handleMessage(Unknown Source) at com.a.a.a.i.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4921) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) at dalvik.system.NativeStart.main(Native Method)

请告诉我,我应该在哪里深入看。最初,我从未遇到过这门课的错误。

1 个答案:

答案 0 :(得分:1)

我认为错误可能在:

List<Integer> listKey = Lists.newArrayList(resolveSerMap.keySet());

键是整数吗?还是字符串?