我有一个空指针异常,代码如下:
void videoCaptureLoop() {
if (!isRecording) {
if (videoCaptureThread != null){
videoCaptureThread.interrupt();
videoCaptureThread = null;
}
return;
}
//Start Video Capture Thread
if (videoCaptureThread==null){
videoCaptureThread = new VideoCaptureLooperThread();
videoCaptureThread.start();
}
//Post capture video on 30 fps interval <<<<--------------NULL POINTER ON NEXT LINE
videoCaptureThread.mHandler.postDelayed(runVideoCaptureLoop, (long) 33.3333333333);
}
Runnable runVideoCaptureLoop = new Runnable(){
@Override
public void run() {
videoCaptureLoop();
}
};
public class VideoCaptureLooperThread extends Thread{
public Handler mHandler;
public void run() {
Looper.prepare();
mHandler = new Handler();
Looper.loop();
}
}
我不断收到空指针异常:
videoCaptureThread.mHandler.postDelayed(runVideoCaptureLoop, (long) 33.3333333333);
麻烦的是我不确定什么是空的,我放了一个断点但一切看起来都很好,直到它崩溃,而且我无法在崩溃前的断点看到任何不同的东西。
我的 VideoCaptureLooperThread 类看起来正确吗?它与 mHandler 需要是静态的有什么关系吗?
错误
09-28 15:50:32.773: E/AndroidRuntime(24931): FATAL EXCEPTION: main
09-28 15:50:32.773: E/AndroidRuntime(24931): java.lang.NullPointerException
09-28 15:50:32.773: E/AndroidRuntime(24931): at com.harmonicprocesses.penelopefree.camera.Pcamera.videoCaptureLoop(Pcamera.java:380)
09-28 15:50:32.773: E/AndroidRuntime(24931): at com.harmonicprocesses.penelopefree.camera.Pcamera$2.onClick(Pcamera.java:338)
09-28 15:50:32.773: E/AndroidRuntime(24931): at android.view.View.performClick(View.java:4240)
谢谢,