0

I'm using the CameraDemo app included with cwac-camera. I'm trying to make the zoom bar change from the main activity using a method updateZoom() but I'm getting a nullpointerexception sometimes from the zoomTo return. Most of the time the zoom will work but then occasionally the program will crash.

Updated zoom:

public void updateZoom()
{
  zoom.setEnabled(false);
   current.zoomTo(zoom.getProgress()).onComplete(new Runnable() {
          @Override
          public void run() {
            zoom.setEnabled(true);
          }
        }).go();
}

Call to updateZoom():

zoom.incrementProgressBy(20);
updateZoom();

Error Logs:

03-01 09:47:55.763: E/AndroidRuntime(31950): FATAL EXCEPTION: main
03-01 09:47:55.763: E/AndroidRuntime(31950): Process: com.commonsware.cwac.camera.demo, PID: 31950
03-01 09:47:55.763: E/AndroidRuntime(31950): java.lang.NullPointerException
03-01 09:47:55.763: E/AndroidRuntime(31950):    at com.commonsware.cwac.camera.CameraFragment.zoomTo(CameraFragment.java:269)
03-01 09:47:55.763: E/AndroidRuntime(31950):    at com.commonsware.cwac.camera.demo.MainActivity.updateZoom(MainActivity.java:163)
03-01 09:47:55.763: E/AndroidRuntime(31950):    at com.commonsware.cwac.camera.demo.MainActivity$1.onPose(MainActivity.java:116)
James
  • 60
  • 5

1 Answers1

0

You are calling updateZoom() at a point when the CameraFragment does not have a CameraView, and so you are getting a NullPointerException when the CameraFragment tries passing the zoomTo() call along to the CameraView.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • how do i make sure that it's not null? the camera output appears on screen yet I'm still getting the nullpointerexception. – James Mar 01 '15 at 15:37
  • @James: "how do i make sure that it's not null?" -- do not call `zoomTo()` until after `onCreateView()` of the `CameraFragment` has completed, or until after you call `setCameraView()` if you are overriding `onCreateView()` and inflating your own layout for the `CameraFragment`. – CommonsWare Mar 01 '15 at 15:43