Android:无法找到资源ID异常

时间:2013-11-25 07:14:17

标签: java android

在我的Android应用程序中,我正在使用achartengine库创建一个饼图。单击按钮时,它会从sqlite数据库中获取数据并绘制饼图。这是我的代码段。

btnpieChart.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    SelectDBAdapter selectDBAdapter = SelectDBAdapter
                            .getDBAdapterInstance(getActivity());
                    try {
                        selectDBAdapter.openDataBase();
                        chartDataMap = selectDBAdapter
                                .getPieChartData(strBusinessUnit,
                                        currentPeriod, currentYear);
                    } catch (Exception e) {
                        selectDBAdapter.close();
                        e.printStackTrace();
                    } finally {
                        selectDBAdapter.close();
                    }
                    System.out.println("chartDataMap === "+ chartDataMap);

                    if (chartDataMap.size() > 0) {
                        for (Map.Entry<String, Double> entry : chartDataMap.entrySet()) {
                            lstBrandNames.add(entry.getKey());
                            lstAchievedVals.add(entry.getValue());
                        }

                        ArrayList<Double> distribution = calc_Percentage(lstAchievedVals);
                        System.out.println("distribution === " + distribution);
                        lstBrandNames = set_lables(lstBrandNames, distribution);

                        CategorySeries distributionSeries = new CategorySeries(
                                "Brands - Achievement Progress");
                        for (int i = 0; i < distribution.size(); i++) {
                            distributionSeries.add(lstBrandNames.get(i), distribution.get(i));
                        }

                        DefaultRenderer defaultRenderer = new DefaultRenderer();
                        defaultRenderer.setApplyBackgroundColor(true);
                        defaultRenderer.setBackgroundColor(Color.WHITE);

                        for (int i = 0; i < distribution.size(); i++) {
                            SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
                            Random rnd = new Random(); 
                            int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));   
                            seriesRenderer.setColor(color);
                            seriesRenderer.setGradientEnabled(false);
                            seriesRenderer.setDisplayChartValues(true);
                            seriesRenderer.setShowLegendItem(false);
                            defaultRenderer.setLabelsTextSize(25);

                            defaultRenderer.addSeriesRenderer(seriesRenderer);
                        }

                        defaultRenderer.setLabelsColor(Color.BLACK);
                        defaultRenderer.setChartTitle("Brands - Achievement Progress");
                        defaultRenderer.setChartTitleTextSize(30);
                        defaultRenderer.setZoomButtonsVisible(true);
                        defaultRenderer.setShowLabels(true);

                        FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                        mChartView = ChartFactory.getPieChartView(getActivity(), distributionSeries, defaultRenderer);
                        ft.replace(mChartView.getId(), new DummySectionFragment(), "NewFragmentTag");
                        ft.addToBackStack(null);
                        ft.commit();


                    }
                }
            });

我的mChartView是,

private GraphicalView mChartView = null;

Log cat说:

11-25 07:03:58.311: E/AndroidRuntime(2706): FATAL EXCEPTION: main
11-25 07:03:58.311: E/AndroidRuntime(2706):    android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.content.res.Resources.getResourceName(Resources.java:1659)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.os.Handler.handleCallback(Handler.java:725)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.os.Looper.loop(Looper.java:137)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at android.app.ActivityThread.main(ActivityThread.java:5039)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at java.lang.reflect.Method.invokeNative(Native Method)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at java.lang.reflect.Method.invoke(Method.java:511)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-25 07:03:58.311: E/AndroidRuntime(2706):     at dalvik.system.NativeStart.main(Native Method)

如果有人能解释这里发生了什么,我将非常感激,如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

检查这些行

  mChartView = ChartFactory.getPieChartView(getActivity(), distributionSeries, defaultRenderer);
  ft.replace(mChartView.getId(), new DummySectionFragment(), "NewFragmentTag");

尤其mChartView.getId()记录此值并检查您的预期