SuitLines icon indicating copy to clipboard operation
SuitLines copied to clipboard

偶尔会出现的闪退请款,是什么原因...求大神看看!!

Open tudou152 opened this issue 6 years ago • 2 comments

Process: com.lixiangdong.weatherforecast, PID: 15881 java.lang.NullPointerException: Attempt to read from field 'float android.graphics.PointF.y' on a null object reference at tech.linjiang.suitlines.SuitLines.drawLines(SuitLines.java:660) at tech.linjiang.suitlines.SuitLines.onDraw(SuitLines.java:437) at android.view.View.draw(View.java:17077) at tech.linjiang.suitlines.SuitLines.draw(SuitLines.java:391) at

private void drawLines(Canvas canvas, int startIndex, int endIndex) { for (int i = 0; i < paths.size(); i++) { paths.get(i).reset(); } for (int i = startIndex; i <= endIndex; i++) { for (int j = 0; j < datas.size(); j++) { Unit current = datas.get(j).get(i); float curY = linesArea.bottom - (linesArea.bottom - current.getXY().y) * current.getPercent(); // 报错包的是这一行代码中的 current.getXY().y if (i == startIndex) { paths.get(j).moveTo(current.getXY().x, curY); continue; } if (lineType == SEGMENT) { paths.get(j).lineTo(current.getXY().x, curY); } else if (lineType == CURVE) { // 到这里肯定不是起始点,所以可以减1 Unit previous = datas.get(j).get(i - 1); // 两个锚点的坐标x为中点的x,y分别是两个连接点的y paths.get(j).cubicTo((previous.getXY().x + current.getXY().x) / 2, linesArea.bottom - (linesArea.bottom - previous.getXY().y) * previous.getPercent(), (previous.getXY().x + current.getXY().x) / 2, curY, current.getXY().x, curY); } if (!needCoverLine && isLineFill() && i == endIndex) { paths.get(j).lineTo(current.getXY().x, linesArea.bottom); paths.get(j).lineTo(datas.get(j).get(startIndex).getXY().x, linesArea.bottom); paths.get(j).close(); } } } drawExsitDirectly(canvas); }

tudou152 avatar Sep 19 '17 07:09 tudou152

我也是 这种情况,同样的错误,出现在连续大量绘图的时候。读了下源码也没搞清楚...

SailFlorve avatar Feb 20 '18 11:02 SailFlorve

重载onMeasure,并尝试把 onSizeChanged 里的 代码 放到里面去,删除 onSizeChanged

whataa avatar Feb 28 '18 01:02 whataa