这是在扩展 View 的 GraphView.java 中。我希望当这个 invalidate(bounds) 被调用时,它应该同时调用 onDraw() .. 这段代码中有什么错误。它给了我这个例外。
01-01 00:45:42.813: E/AndroidRuntime(1586): FATAL EXCEPTION: Timer-2 01-01 00:45:42.813: E/AndroidRuntime(1586): java.lang.NullPointerException 01-01 00:45:42.813: E/AndroidRuntime(1586): at android.view.View.invalidate(View.java:8467) 01-01 00:45:42.813: E/AndroidRuntime(1586): at com.cdl.mircam.GraphView$1.run(GraphView.java:327) 01-01 00:45:42.813: E/AndroidRuntime(1586): at java.util.Timer$TimerImpl.run(Timer.java:284)
@Override
public void onDraw(Canvas c)
{
super.onDraw(c);
drawStuff(c);
}
public void drawStuff(Canvas canvas)
{
try
{
PlotRealTimeGraph(canvas);
bounds = new Rect(chanX_count1+0, 0, chanX_count1+5, graphheight);
canvas.drawRect(bounds,myPaint);
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
public void InvalidatePlotRealTimeGraph()
{
Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run()
{
invalidate(bounds);
}
},1000,40);
}
有什么帮助吗?请!!!