gpt4 book ai didi

android - 随机生成器的 XY 图

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:49 25 4
gpt4 key购买 nike

我正在尝试为我的随机生成器创建一个动态图表,以保持抽取值。对于我使用的图表 AChartEngine .我很清楚我的方法是使用异步任务机制通过动态图表的后台线程进行更新。但我无法使用 AChartEngine 库获得基本的 XY 图表。应用程序每次都会崩溃。这是我的基本 XY 图表代码。

package com.example.graph2;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class Graph2Activity extends Activity {
private XYMultipleSeriesDataset RNG_Dataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer RNG_Renderer = new XYMultipleSeriesRenderer();
public XYSeries RNG_CurrentSeries;
private GraphicalView RNG_ChartView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


RNG_Renderer.setAxisTitleTextSize(16);
RNG_Renderer.setChartTitleTextSize(20);
RNG_Renderer.setLabelsTextSize(15);
RNG_Renderer.setLegendTextSize(15);
RNG_Renderer.setMargins(new int[] {20, 30, 15, 0});
RNG_Renderer.setAxesColor(Color.YELLOW);

String seriesTitle = "RNG";
XYSeries series = new XYSeries(seriesTitle);

RNG_Dataset.addSeries(series);
RNG_CurrentSeries = series;

XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
RNG_Renderer.addSeriesRenderer(renderer);
setContentView(R.id.RNGchart);
}

protected void onResume() {
if (RNG_ChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.RNGchart);
RNG_ChartView = ChartFactory.getLineChartView(this, RNG_Dataset, RNG_Renderer);

layout.addView(RNG_ChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// boolean enabled = HRDataset.getSeriesCount() > 0;
// setSeriesEnabled(enabled);
} else {
RNG_ChartView.repaint();
}
}
}

这是我使用的 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RNGchart" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="300px"
android:layout_weight="1" />

有人可以告诉我哪里出错了吗?这是异常日志:

10-10 17:20:52.761: ERROR/AndroidRuntime(335): FATAL EXCEPTION: main
10-10 17:20:52.761: ERROR/AndroidRuntime(335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.graph2/com.example.graph2.Graph2Activity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:507)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.content.res.Resources.getLayout(Resources.java:731)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.Activity.setContentView(Activity.java:1657)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at com.example.graph2.Graph2Activity.onCreate(Graph2Activity.java:44)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-10 17:20:52.761: ERROR/AndroidRuntime(335): ... 11 more


Here is the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.graph2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Graph2Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="org.achartengine.chartdemo.demo.chart.XYChartBuilder" />
<activity android:name="org.achartengine.GraphicalActivity" />
<activity android:name=".GeneratedChartDemo" />
</application>
</manifest>

最佳答案

您可以从 here 查看我的完整Demo

试试这个,

<activity android:name="com.example.graph2.Graph2Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

并确保您的 Graph2Activity Activity 位于 com.example.graph2 包内。

关于android - 随机生成器的 XY 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7711986/

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