将数据添加到图表时,我收到此NullPointerException。这是我的一些数据(没有什么是空的):
11-21 21:09:36.286: I/System.out(10682): 51.0 | -13.3 | 77.0
11-21 21:09:36.286: I/System.out(10682): 55.0 | -13.0 | 78.0
11-21 21:09:36.294: I/System.out(10682): 52.0 | -12.8 | 79.0
11-21 21:09:36.294: I/System.out(10682): 57.0 | -12.8 | 79.0
11-21 21:09:36.294: I/System.out(10682): 57.0 | -12.7 | 80.0
11-21 21:09:36.294: I/System.out(10682): 58.0 | -11.6 | 80.0
11-21 21:09:36.294: I/System.out(10682): 57.0 | -10.6 | 80.0
11-21 21:09:36.294: I/System.out(10682): 58.0 | -9.1 | 81.0
11-21 21:09:36.301: I/System.out(10682): 59.0 | -8.9 | 82.0
11-21 21:09:36.301: I/System.out(10682): 59.0 | -8.6 | 82.0
11-21 21:09:36.301: I/System.out(10682): 59.0 | -8.8 | 82.0
11-21 21:09:36.301: I/System.out(10682): 59.0 | -9.0 | 83.0
11-21 21:09:36.301: I/System.out(10682): 58.0 | -9.5 | 83.0
11-21 21:09:36.301: I/System.out(10682): 57.0 | -9.6 | 83.0
11-21 21:09:36.301: I/System.out(10682): 58.0 | -9.3 | 83.0
错误日志显示:
11-21 21:09:36.426: E/AndroidRuntime(10682): FATAL EXCEPTION: main
11-21 21:09:36.426: E/AndroidRuntime(10682): java.lang.NullPointerException
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.view.ViewConfiguration.get(ViewConfiguration.java:323)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.view.View.<init>(View.java:3271)
11-21 21:09:36.426: E/AndroidRuntime(10682): at org.achartengine.GraphicalView.<init>(GraphicalView.java:91)
11-21 21:09:36.426: E/AndroidRuntime(10682): at org.achartengine.ChartFactory.getLineChartView(ChartFactory.java:70)
11-21 21:09:36.426: E/AndroidRuntime(10682): at com.jasonflaherty.snoteldata.BCMarkerInformation$CheckTask.onPostExecute(BCMarkerInformation.java:321)
11-21 21:09:36.426: E/AndroidRuntime(10682): at com.jasonflaherty.snoteldata.BCMarkerInformation$CheckTask.onPostExecute(BCMarkerInformation.java:1)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.os.AsyncTask.finish(AsyncTask.java:631)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.os.Looper.loop(Looper.java:137)
11-21 21:09:36.426: E/AndroidRuntime(10682): at android.app.ActivityThread.main(ActivityThread.java:5289)
11-21 21:09:36.426: E/AndroidRuntime(10682): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 21:09:36.426: E/AndroidRuntime(10682): at java.lang.reflect.Method.invoke(Method.java:525)
11-21 21:09:36.426: E/AndroidRuntime(10682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
11-21 21:09:36.426: E/AndroidRuntime(10682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
11-21 21:09:36.426: E/AndroidRuntime(10682): at dalvik.system.NativeStart.main(Native Method)
第321行有我的图表设置:
mChart = ChartFactory.getLineChartView(ctx, mDataset, mRenderer);
我已将其他数据添加到图表设置中,因此我不确定此NPE的来源。根据我的logcat,只是一个FYI,它在代码中没有达到这么远,但我有一个像这样的表布局设置:
<TableRow
android:id="@+id/GraphRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#59473d"
android:gravity="center_horizontal" >
<LinearLayout
android:id="@+id/chart"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_span="4"
android:background="#000000"
android:orientation="horizontal" />
</TableRow>
我尝试将图形添加到只有一个简单的xml布局,只有线性布局...所以我很确定这不是问题。
我设置了布局:LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
我将其添加到布局:layout.addView(mChart);
关于从哪里开始的任何想法?我现在不知所措。还有什么我可以添加到这个问题吗?
答案 0 :(得分:1)
您传递给context
中方法的ChartFactory
似乎是null
。