膨胀类片段时出错(与 ShinobiCharts 相关)



我收到一个"膨胀类片段时出错"。是由于我的 xml 文件中的错误吗?我有一种感觉,这可能与我正在使用的命名空间有关,但我不确定......

这是日志猫:

12-30 11:02:41.525: I/dalvikvm(8714): Could not find method 
com.example.gameexpensetracker.Chart_screen_activity.getFragmentManager, referenced from method com.example.gameexpensetracker.Chart_screen_activity.pieGraphData
12-30 11:02:41.525: W/dalvikvm(8714): VFY: unable to resolve virtual method 5181: Lcom/example/gameexpensetracker/Chart_screen_activity;.getFragmentManager ()Landroid/app/FragmentManager;
12-30 11:02:41.535: D/dalvikvm(8714): VFY: replacing opcode 0x6e at 0x0204
12-30 11:02:41.535: D/dalvikvm(8714): VFY: dead code 0x0207-02c9 in Lcom/example/gameexpensetracker/Chart_screen_activity;.pieGraphData ()V
12-30 11:02:41.555: D/AndroidRuntime(8714): Shutting down VM
12-30 11:02:41.555: W/dalvikvm(8714): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-30 11:02:41.565: E/AndroidRuntime(8714): FATAL EXCEPTION: main
12-30 11:02:41.565: E/AndroidRuntime(8714): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gameexpensetracker/com.example.gameexpensetracker.Chart_screen_activity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.os.Looper.loop(Looper.java:123)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread.main(ActivityThread.java:3683)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at java.lang.reflect.Method.invokeNative(Native Method)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at java.lang.reflect.Method.invoke(Method.java:507)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at dalvik.system.NativeStart.main(Native Method)
12-30 11:02:41.565: E/AndroidRuntime(8714): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.Activity.setContentView(Activity.java:1657)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at com.example.gameexpensetracker.Chart_screen_activity.onCreate(Chart_screen_activity.java:27)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-30 11:02:41.565: E/AndroidRuntime(8714):     ... 11 more
12-30 11:02:41.565: E/AndroidRuntime(8714): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.gameexpensetracker-2.apk]
12-30 11:02:41.565: E/AndroidRuntime(8714):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
12-30 11:02:41.565: E/AndroidRuntime(8714):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
12-30 11:02:41.565: E/AndroidRuntime(8714):     ... 20 more

下面是 XML 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Chartscreenactivity" >
<fragment
    class="com.shinobicontrols.charts.ChartFragment"
    android:id="@+id/chart"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

下面是活动的相关代码:

ChartFragment chartFragment =
                                    (ChartFragment) getFragmentManager().findFragmentById(R.id.chart);
                            // Get the a reference to the ShinobiChart from the ChartFragment
                            ShinobiChart shinobiChart = chartFragment.getShinobiChart();

                            shinobiChart.setLicenseKey("UXbN8mQk0U/byjLMjAxNDAxMjJpbmZvQHNoaW5vYmljb250cm9scy5jb20=1rmCjO7D5wQQxbCcpm28bXkLR" +
                                    "/7MtHh+IrFH93SspNfyW8J5Kf6xZfQ7dUJGFNDwdYkZGUaabHs3vezwOc9t+eJjMmVLkhRkVnnN47JIl3ir/cDGz36Ru2bC7SexLSZhkj0" +
                                    "bXL69ISkSVMvyJZsbGm7gpby0=BQxSUisl3BaWf/7myRmmlIjRnMU2cA7q+/03ZX9wdj30RzapYANf51ee3Pi8m2rVW6aD7t6Hi4Qy5vv9xpa" +
                                    "QYXF5T7XzsafhzS3hbBokp36BoJZg8IrceBj742nQajYyV7trx5GIw9jy/V6r0bvctKYwTim7Kzq+YPWGMtqtQoU=PFJTQUtleVZhbHVlPjxNb" +
                                    "2R1bHVzPnh6YlRrc2dYWWJvQUh5VGR6dkNzQXUrUVAxQnM5b2VrZUxxZVdacnRFbUx3OHZlWStBK3pteXg4NGpJbFkzT2hGdlNYbHZDSjlKVGZQ" +
                                    "TTF4S2ZweWZBVXBGeXgxRnVBMThOcDNETUxXR1JJbTJ6WXA3a1YyMEdYZGU3RnJyTHZjdGhIbW1BZ21PTTdwMFBsNWlSKzNVMDg5M1N4b2hCZlJ5RHd" +
                                    "EeE9vdDNlMD08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjwvUlNBS2V5VmFsdWU+");
                            SimpleDataAdapter<String, Double> dataAdapter = new SimpleDataAdapter<String, Double>();
                            dataAdapter.add(new DataPoint<String, Double>("Action", actionTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Adventure", adventureTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("MMO", MMOTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Puzzle", puzzleTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Racing", racingTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("RPG", rpgTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Sim", simulationTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Sports",sportsTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Strategy", strategyTotalDB));
                            dataAdapter.add(new DataPoint<String, Double>("Other", otherTotalDB));

                            PieSeries series = new PieSeries();
                            series.setDataAdapter(dataAdapter);
                            shinobiChart.addSeries(series);

尽管ShinobiCharts支持低至API Level 9(Gingerbread),但片段仅在API Level 11中引入。因此,您需要使用支持库。

从入门指南:

提示:要支持低至 API 9:Android 2.3(姜饼)的设备,您需要使用 SupportChartFragment 而不是 ChartFragment(在 XML 和 Java 源代码中)。此外,您需要更改ShinobiQuickStartActivity以扩展FragmentActivity而不是Activity,并使用 getSupportFragmentManager() 方法而不是 getFragmentManager() 。您的项目需要参考 Android 支持库才能执行此操作。

(通过: http://www.shinobicontrols.com/android/shinobicharts/quickstartguide/draw-a-simple-chart/)

相关内容

  • 没有找到相关文章

最新更新