這是GraphView.java,它擴展了View。我希望當這個無效(邊界)被調用時,同時它應該調用onDraw()..這個代碼中的錯誤是什麼。它給了我這個例外。Android 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);
}
任何幫助嗎?請!!!
GraphView.java中第327行的內容是什麼? –
@ Mocialov GraphView.java是我寫這個代碼的文件。這個類擴展了查看 – user1844130
太好了! 327線是什麼? –