谁能告诉我这个Logcat要求的是什么?

时间:2012-09-22 07:00:23

标签: android bar-chart

  

可能重复:
  Issues while showing a barchart in android

有人能告诉我这个Logcat要求的是什么吗?

现在我正在尝试使用网络服务在Android中创建一个条形图。这意味着我从网络服务获取x和y轴值。

logcat的

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

BarGraphActivity.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;
 }}

2 个答案:

答案 0 :(得分:1)

您在以下行中有一个NPE:

int seriesLength = v.length;

由于您的代码显示正在v填充values[] List,因此您正在使用的索引List可能为空。

答案 1 :(得分:0)

您正在从之前的活动中收到空意图。

这一行,

Bundle extras = getIntent().getExtras();

检查您的意图是否有任何价值。 如果它不为null,那么这一行肯定有一个空值,

arr_val = extras.getIntArray("goto_next_page");