gpt4 book ai didi

android - android 问题中的 donut chart

转载 作者:行者123 更新时间:2023-12-04 16:13:00 25 4
gpt4 key购买 nike

嗨,我想在 android 中制作一个 donut chart 。我有一个很好的例子。我添加了库,项目没有显示错误。但是在运行时,它在logcat中出现以下错误。

12-12 08:46:53.083: E/AndroidRuntime(1467): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.artfulbits.aiCharts.DoughnutSample/com.artfulbits.aiCharts.DoughnutSample.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.artfulbits.aiCharts.ChartView
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.os.Looper.loop(Looper.java:137)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread.main(ActivityThread.java:5041)
12-12 08:46:53.083: E/AndroidRuntime(1467): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 08:46:53.083: E/AndroidRuntime(1467): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 08:46:53.083: E/AndroidRuntime(1467): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-12 08:46:53.083: E/AndroidRuntime(1467): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-12 08:46:53.083: E/AndroidRuntime(1467): at dalvik.system.NativeStart.main(Native Method)
12-12 08:46:53.083: E/AndroidRuntime(1467): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.artfulbits.aiCharts.ChartView
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-12 08:46:53.083: E/AndroidRuntime(1467): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.Activity.setContentView(Activity.java:1881)
12-12 08:46:53.083: E/AndroidRuntime(1467): at com.artfulbits.aiCharts.DoughnutSample.MainActivity.onCreate(MainActivity.java:18)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.Activity.performCreate(Activity.java:5104)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-12 08:46:53.083: E/AndroidRuntime(1467): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-12 08:46:53.083: E/AndroidRuntime(1467): ... 11 more

主要 Activity 的代码是
import com.artfulbits.aiCharts.ChartView;
import com.artfulbits.aiCharts.Base.ChartSeries;
import com.artfulbits.aiCharts.Types.ChartDoughnutType;
import com.artfulbits.aiCharts.Types.ChartPieType.LabelStyle;

public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ChartView chartView = (ChartView) findViewById(R.id.chartView);
ChartSeries series = chartView.getSeries().get(0);

String[] labels = { "milk", "yeast", "flour",
"eggs", "butter", "salt", "water", "sugar" };
int[] weights = {180, 12, 450, 100, 100, 10, 250, 250 };

for (int i = 0; i < weights.length; i++)
series.getPoints().addXY(i, weights[i]).setLabel(labels[i]);

series.setAttribute(ChartDoughnutType.LABEL_STYLE, LabelStyle.OutsideColumn);
series.setAttribute(ChartDoughnutType.OPTIMIZE_POINTS, Boolean.FALSE);
}
}

main.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<com.artfulbits.aiCharts.ChartView
android:id="@+id/chartView"
chart="@xml/chart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

最佳答案

请确保您的源代码中有一个 res/xml 目录,并且它包含一个如下所示的 xml 文件。

图表.xml

<?xml version="1.0" encoding="utf-8"?>
<ai:chart xmlns:ai="http://www.artfulbits.com/android/aiCharts">
<ai:area />
<ai:series type="Doughnut" showLabel="true"/>
<ai:title text="Doughnut ingredients"/>
</ai:chart>

查看完整示例 ArtfulBits

关于android - android 问题中的 donut chart ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20538836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com