sinat_17033687
小小的努力中
2017-07-12 15:26

Android自定义View,空指针?

  • android
  • 指针

private void drawScale(Canvas canvas)
{
canvas.save();
canvas.translate(getWidth() / 2 ,getHeight() / 2);

    canvas.rotate(-133);
    dialPaint.setColor(Color.parseColor("#3CB7EA"));
    for (int i = 0; i < (temperature - minTemp)* angleRate;i++)
    {
        canvas.drawLine(0,-dialRadius,0,-dialRadius + scaleHeight,dialPaint);
        canvas.rotate(4.5f);
    }

    canvas.rotate(90);
    dialPaint.setColor(Color.parseColor("#E37364"));

    for (int i = 0; i < (temperature - minTemp) * angleRate; i++)
    {
        canvas.drawLine(0, -dialRadius, 0,-dialRadius + scaleHeight,dialPaint);
    }
    canvas.restore();

}

07-12 15:20:16.438 3814-3814/com.huawei.tempcontrolview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.huawei.tempcontrolview, PID: 3814
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Paint.setColor(int)' on a null object reference
at com.huawei.tempcontrolview.TempControlView.drawScale(TempControlView.java:168)
at com.huawei.tempcontrolview.TempControlView.onDraw(TempControlView.java:151)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答

为你推荐

换一换