Я хочу нарисовать график, который отслеживает прогресс веса пользователя,
Я пишу метод, который я могу вызвать в событии onCreat,
Это мой код:
public void drawGraph(){
Display display = getWindowManager().getDefaultDisplay();
private int width = display.getWidth();
private int height = display.getHeight();
Paint paint = new Paint();
Canvas canvas =new Canvas();
paint.setColor(Color.GRAY);
canvas.drawLine(0, 0, 0, height, paint); // the x-axes represent the date
canvas.drawLine(0, height, width, height, paint); // the y-axes represent the weight
paint.setColor(Color.RED);
canvas.drawLine(0, max, width, max, paint); //draw the maximum healthy weight
paint.setColor(Color.YELLOW);
canvas.drawLine(0, min, width, min, paint); // draw the minimum healthy weight
paint.setColor(Color.GREEN);
canvas.drawLine(0, gW, width, gW, paint); // draw the goal weight
int xDis = width/weekNumbers;
int y;
Path path = new Path();
for (int i = 0; i <= Weightvalues; i++){
Cursor c = db.rawQuery("SELECT CURRENTWEIGHT FROM WEIGHT WHERE DATECREATED > " + startDate, null);
int weight;
if (c!=null){
if (c.moveToFirst()){
do{
weight = c.getInt(0);
// I want now to find out for each entry the point represent it on the graph
y = Math.round(weight * y / range); //range is the difference between the maximum weight and the minimum weight
if (i==1)
path.moveTo(0, y);
else
path.lineTo(0 + i*xDis, height-y);
}while(c.moveToNext());
}
}
}
paint.setColor(Color.BLUE);
canvas.drawPath(path, paint);
}
это событие onCreat
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.weight_chart);
helper = new DataBaseHelper(this);
drawGraph();
}
, когда я запускаю программу, я сталкиваюсь с этой ошибкой
ERROR/AndroidRuntime(738): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{*********.WeightChart}: java.lang.NullPointerException
Может ли кто-нибудь проверить ее для меня и сказать, где я ошибся
С наилучшими пожеланиями