saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
3k stars 1.21k forks source link

NullpointerException Error #573

Open jeranio opened 4 years ago

jeranio commented 4 years ago

2020-09-10 20:39:40.890 5811-5867/com.serenegiant.usbcameratest2 E/MainActivity: run: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.serenegiant.usb.UVCCamera.setFrameCallback(com.serenegiant.usb.IFrameCallback, int)' on a null object reference

The error occurs when this line is executed:

mUVCCamera.setFrameCallback(mFrameCallback, UVCCamera.PIXEL_FORMAT_RGB565);

I followed the instructions to the letter from issue #7 but I get the above error. Normally this would be because I didn't instantiate the view or some variable. This is stock standard usbcameratest2 with the modifications as per the guide. I triple checked that I got all the steps correct before posting.

I did change this line

uvc_image = (ImageView)findViewById(R.id.imageview); to uvc_image = (ImageView)findViewById(R.id.callback_imageview);

to match XML file in the instructions.

I also had to makes these changes to the manifest and styles XML, otherwise I got error about theming issues.

//manifest android:theme="@style/Theme.AppCompat.NoActionBar"

//styles `

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">  //*************changed
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->

`

Update: I set a breakpoint and just before the offending line is called I can only see mUVCCamera = null but I have a preview screen okay.