Camera (takepicture) from runnable

erezposner

New Member
Im new to android , i am trying to implement a timer that takes a picture every period of time.

i dont know where to put the "red" line emphesized in the code, in order to take the picture, or why im given the following error.


ERROR/AndroidRuntime(19428): java.lang.NullPointerException
ERROR/AndroidRuntime(19428): at timer.erez.temp.TimertempActivity$1.run(TimertempA ctivity.java:69)
ERROR/AndroidRuntime(19428): at android.os.Handler.handleCallback(Handler.java:587 )
ERROR/AndroidRuntime(19428): at android.os.Handler.dispatchMessage(Handler.java:92 )
ERROR/AndroidRuntime(19428): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(19428): at android.app.ActivityThread.main(ActivityThread.jav a:4627)


My code

public class TimertempActivity extends Activity {
private static final String TAG = "CameraDemo";
private Timer MyTimer;
Preview preview; // <1>


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview = new Preview(this); // <3>


((FrameLayout) findViewById(R.id.preview)).addView(preview);



MyTimer = new Timer();
MyTimer.schedule(new TimerTask(){
@Override
public void run(){
TimerMethod();


}
},0,15000);
}
private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable() {



@Override
public void run() {
preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
};
 
Top