1

I tried to make this code work, but I have this error and I don't know how solve it:

03-23 21:51:44.705: E/AndroidRuntime(1628): java.lang.NullPointerException 03-23 21:51:44.705: E/AndroidRuntime(1628): at org.projectproto.objtrack.SampleViewBase.surfaceCreated(SampleViewBase.java:107)

3
  • 1
    According to the LogCat, you should start on line 107 in SampleBaseView. A variable on that line is null... If it is mCamera please read about open() and how you'll have trouble if you are using an emulator but haven't setup a camera. Commented Mar 23, 2013 at 22:45
  • 1
    Show us what's in line number 107 in SampleViewBase.java file. Commented Mar 23, 2013 at 22:49
  • that what I have in line 107 to 115: mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { synchronized (SampleViewBase.this) { System.arraycopy(data, 0, mFrame, 0, data.length); SampleViewBase.this.notify(); } camera.addCallbackBuffer(mBuffer); } }); Commented Mar 23, 2013 at 22:56

1 Answer 1

1

mCamera seems to be null because Camera.open(); did not return a reference to a camera.

There are different possibilities for that. One might be a missing camera permission in your manifest file. Check it for <uses-permission android:name="android.permission.CAMERA" />

At my Nexus 7 I experienced a problem with Camera.open() as well because for some reason Camera.open(0), which is the same as Camera.open() returned null but Camera.open(1) returned a Camera object of my front camera. May be this is a general issue with devices which only have a frontcamera, but I don't know.

Anyway, this should be the place for you to look at.

Camera | Android Developers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.