可能重复:
在 android 中显示条形图时出现问题
谁能告诉我这个 Logcat 的要求是什么?
现在我正在尝试使用 web 服务在 android 中创建一个条形图。这意味着我正在从 web 服务获取 x 和 y 轴值。
日志猫
09-22 12:23:04.847: I/Process(310): Sending signal. PID: 310 SIG: 9
09-22 12:23:50.852: W/KeyCharacterMap(339): No keyboard for id 0
09-22 12:23:50.852: W/KeyCharacterMap(339): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-22 12:23:59.532: D/AndroidRuntime(339): Shutting down VM
09-22 12:23:59.532: W/dalvikvm(339): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-22 12:23:59.542: E/AndroidRuntime(339): FATAL EXCEPTION: main
09-22 12:23:59.542: E/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xmlparsing_test/com.example.xmlparsing_test.BarGraphActivity}: java.lang.NullPointerException
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.os.Looper.loop(Looper.java:123)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-22 12:23:59.542: E/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 12:23:59.542: E/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:521)
09-22 12:23:59.542: E/AndroidRuntime(339): at com. android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-22 12:23:59.542: E/AndroidRuntime(339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-22 12:23:59.542: E/AndroidRuntime(339): at dalvik.system.NativeStart.main(Native Method)
09-22 12:23:59.542: E/AndroidRuntime(339): Caused by: java.lang.NullPointerException
09-22 12:23:59.542: E/AndroidRuntime(339): at com.example.xmlparsing_test.BarGraphActivity.buildBarDataset(BarGraphActivity.java:122)
09-22 12:23:59.542: E/AndroidRuntime(339): at com.example.xmlparsing_test.BarGraphActivity.DrawGraph(BarGraphActivity.java:64)
09-22 12:23:59.542: E/AndroidRuntime(339): at com.example.xmlparsing_test.BarGraphActivity.onCreate(BarGraphActivity.java:26)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-22 12:23:59.542: E/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-22 12:23:59.542: E/AndroidRuntime(339): ... 11 more
条形图活动.java
public class BarGraphActivity extends Chart
{
int[] arr_val;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
DrawGraph();
}
public void DrawGraph()
{
Bundle extras = getIntent().getExtras();
if(extras != null)
{
arr_val = extras.getIntArray("goto_next_page");
}else
{};
List<int[]> values = new ArrayList<int[]>();
values.add(arr_val);
int[] colors = new int[] { Color.WHITE, Color.BLACK};
String[] titles = new String[] { " Orders percentage",""};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer, "some texts", " ", " ",0,arr_val, 0,arr_val, Color.GRAY, Color.LTGRAY);
renderer.setXLabels(1);
renderer.addXTextLabel(2, "orderNo");
renderer.addYTextLabel(2, "freight");
renderer.setPanEnabled(true, false);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer,Type.DEFAULT);
}
public XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
// creates a SeriesRenderer and initializes it with useful default values as well as colors
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(15);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
renderer.addSeriesRenderer(r);
}
return renderer;
}
public void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
String yTitle, int xMin, int[] arr_val2, int yMin, int[] arr_val3, int axesColor,int labelsColor)
{
// sets lots of default values for this renderer
renderer.setChartTitle(title);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setYAxisMin(yMin);
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK);
}
public XYMultipleSeriesDataset buildBarDataset(String[] titles, List<int[]> values)
{
// adds the axis titles and values into the dataset
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
int[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}}