Я хочу построить RPM двигателя. Во-первых, я хочу показать пустой сюжет без данных. Приложение не падает, но я получаю бесконечную ошибку на мониторе Android, и я не вижу сюжета. Я использую библиотеку Android Plot.Исключение при рендеринге Сюжет (null at com.androidplot.Plot.renderOnCanvas)
Я подтвердил образец кода из графика определения ориентации в реальном времени. Я где-то читал, чтобы добавить один пункт в сюжет, чтобы предотвратить сбой, но он не работает.
Я также нашел в logcat некоторые другие ошибки до null pointer exception
, но я не могу вставить его здесь, потому что это большие данные.
W/System.err: java.lang.NoSuchMethodException: getDomainLabelPaint []
Это форма LogCat андроид монитор (не мог опубликовать все 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)