1. Download our Official Android App: Forums for Android!

Apps Camera (takepicture) from runnable

Discussion in 'Android Development' started by erezposner, Jul 31, 2011.

  1. erezposner

    erezposner Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 10, 2011

    Jun 10, 2011
    5
    0
    5
    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(TimertempActivity.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.java: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);
    }
    };
     

    Advertisement

Share This Page

Loading...