渲染Plot时出现异常(com.androidplot.Plot.renderOnCanvas为null)

时间:2016-01-23 19:16:46

标签: android nullpointerexception androidplot

我想绘制引擎RPM。首先,我想显示没有数据的空图。应用程序没有崩溃,但我在Android显示器上得到无穷无尽的错误,我不会看到情节。我使用Android Plot库。

我确认了来自实时方向传感器图的代码示例。我在某个地方读到了一点来绘制图以防止崩溃,但它没有用。

我还在logcat中发现了stdbool.h之前的其他一些错误,但我无法将其粘贴到此处,因为这是大数据。

null pointer exception

这是logcat形式的android监视器(不能发布所有logcat,所以我在http://pastebin.com/raw/GLEVRYXe上发布了休息)

W/System.err: java.lang.NoSuchMethodException: getDomainLabelPaint []

以下是代码方的代码段:

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);
    }

(完整代码在github

1 个答案:

答案 0 :(得分:0)

首先,看起来你可能正在使用Proguard混淆。如果是这种情况,这很可能导致 NoSuchMethodException ;您正在使用Configurator从XML动态配置您的绘图,而XML又使用反射来完成它的工作。如果预期的名称已被混淆,那么它将以上述方式失败。

尝试禁用混淆或将其添加到proguard配置中:

-keep class com.androidplot.** {
  public *;
}

如果这也解决了NPE问题我也不会感到惊讶。