我想繪製引擎RPM。首先,我想顯示沒有數據的空圖。應用程序不會崩潰,但我在Android監視器上得到無盡的錯誤,我沒有看到情節。我使用Android Plot庫。呈現繪圖時發生異常(null at com.androidplot.Plot.renderOnCanvas)
我從實時定向傳感器圖確認代碼示例。我在某處讀了一點,爲了避免崩潰而添加一點情節,但它不起作用。
我在logcat中也發現null pointer exception
之前的一些其他錯誤,但我可以,因爲是大數據未粘貼到此處。
W/System.err: java.lang.NoSuchMethodException: getDomainLabelPaint []
這是logcat的形式的Android顯示器(無法發佈所有logcat的,所以我貼在http://pastebin.com/raw/GLEVRYXe休息)
E/com.androidplot.Plot: Exception while rendering Plot.
E/com.androidplot.Plot: java.lang.NullPointerException
E/com.androidplot.Plot: at com.androidplot.Plot.renderOnCanvas(Plot.java:776)
E/com.androidplot.Plot: at com.androidplot.Plot$1.run(Plot.java:344)
E/com.androidplot.Plot: at java.lang.Thread.run(Thread.java:841)
E/com.androidplot.Plot: Exception while rendering Plot
下面是從代碼端片段:
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
btnPreSetup = (Button) view.findViewById(R.id.btnPreSetup);
btnStartTelemetry = (Button) view.findViewById(R.id.btnStartTel);
tvRpm = (TextView) view.findViewById(R.id.tvRpm);
tvLoad = (TextView) view.findViewById(R.id.tvLoad);
tvCoolantTemp = (TextView) view.findViewById(R.id.tvCoolantTepm);
tvSpeed = (TextView) view.findViewById(R.id.tvSpeed);
tvAirTemp = (TextView) view.findViewById(R.id.tvTempAirFlow);
tvThrottle = (TextView) view.findViewById(R.id.tvThrottle);
// setup the APR History plot:
rpmPlotGraph = (XYPlot) view.findViewById(R.id.rpmHistoryPlot);
rpmSeries = new SimpleXYSeries("RPM");
rpmSeries.useImplicitXVals();
rpmSeries.addLast(1, 1000);
//Ustawienia wykresu
rpmPlotGraph.setRangeBoundaries(800, 5000, BoundaryMode.FIXED); //TODO: FIX
rpmPlotGraph.setDomainBoundaries(0, HISTORY_SIZE, BoundaryMode.FIXED);
rpmPlotGraph.addSeries(rpmSeries,
new LineAndPointFormatter(
Color.rgb(100, 100, 200), null, null, null));
//aprHistoryPlot.addSeries(pitchHistorySeries, new LineAndPointFormatter(Color.rgb(100, 200, 100), null, null, null));
//aprHistoryPlot.addSeries(rollHistorySeries, new LineAndPointFormatter(Color.rgb(200, 100, 100), null, null, null));
rpmPlotGraph.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
rpmPlotGraph.setDomainStepValue(HISTORY_SIZE/10);
rpmPlotGraph.setTicksPerRangeLabel(3);
rpmPlotGraph.setDomainLabel("Sample Index");
rpmPlotGraph.getDomainLabelWidget().pack();
rpmPlotGraph.setRangeLabel("Angle (Degs)");
rpmPlotGraph.getRangeLabelWidget().pack();
rpmPlotGraph.setRangeValueFormat(new DecimalFormat("#"));
rpmPlotGraph.setDomainValueFormat(new DecimalFormat("#"));
redrawer = new Redrawer(Arrays.asList(new Plot[]{rpmPlotGraph}), 100, false);
}
和查看代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="pl.rychlinski.damian.mobilnatelemetria.BluetoothFragment">
...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.androidplot.xy.XYPlot
style="@style/simple_xy"
android:id="@+id/rpmHistoryPlot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:layout_weight="1"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
androidPlot.backgroundPaint.color="#000000"
androidPlot.borderPaint.color="#000000"
androidplot.renderMode="use_background_thread"
androidPlot.title="History"
androidPlot.domainLabel="Domain"
androidPlot.rangeLabel="Range"
androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
androidPlot.graphWidget.backgroundPaint.color="#000000"
androidPlot.graphWidget.gridBackgroundPaint.color="#000000"
androidPlot.graphWidget.marginTop="20dp"
androidPlot.graphWidget.marginLeft="15dp"
androidPlot.graphWidget.marginBottom="25dp"
androidPlot.graphWidget.marginRight="10dp"
androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
/>
</LinearLayout>
(全碼是github)