dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
992 stars 580 forks source link

OnCreate - java.lang.NullPointerException: Attempt to invoke virtual method 'dji.midware.data.config.P3.ProductType dji.midware.data.manager.P3.DJIProductManager.c()' #177

Closed jknair0 closed 6 years ago

jknair0 commented 7 years ago

When i am using this in my activity onCreate() the app crashs

binding.body.droneLiveView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                if (codecManager == null) {
                    codecManager = new DJICodecManager(BaseSurveyActivity.this.getApplicationContext(), surface, width, height, UsbAccessoryService.VideoStreamSource.Fpv);
                }
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                if (codecManager != null) {
                    codecManager.cleanSurface();
                    codecManager = null;
                }
                return false;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surface) {

            }
        });
FATAL EXCEPTION: main
                                                                  Process: com.package.djiapp, PID: 4574
                                                                  java.lang.NullPointerException: Attempt to invoke virtual method 'dji.midware.data.config.P3.ProductType dji.midware.data.manager.P3.DJIProductManager.c()' on a null object reference
                                                                      at dji.midware.media.e.c.b.a(Unknown Source)
                                                                      at dji.midware.media.e.c.b.a(Unknown Source)
                                                                      at dji.midware.media.e.c.b.a(Unknown Source)
                                                                      at dji.sdk.codec.DJICodecManager.<init>(Unknown Source)
                                                                      at com.package.djiapp.screens.survey.BaseSurveyActivity$2.onSurfaceTextureAvailable(BaseSurveyActivity.java:142)
                                                                      at android.view.TextureView.getHardwareLayer(TextureView.java:368)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16511)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.draw(View.java:17544)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16534)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1379)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16529)
                                                                      at android.view.View.draw(View.java:17310)
                                                                      at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
                                                                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
                                                                      at android.view.View.draw(View.java:17544)
                                                                      at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:3187)
                                                                      at android.view.View.updateDisplayListIfDirty(View.java:16534)
                                                                      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:325)
                                                                      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:331)
                                                                      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:366)
                                                                      at android.view.ViewRootImpl.draw(ViewRootImpl.java:3251)
                                                                      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3050)
                                                                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2632)
                                                                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1544)
                                                                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7613)
                                                                    at android.view.Choreographer$CallbackRecord.run(Chore

I am using android studio 2.3.3 dji sdk 4.3.2

jknair0 commented 7 years ago
FATAL EXCEPTION: main 
Process: com.sensehawk.link, PID: 31385
                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'dji.midware.data.config.P3.ProductType dji.midware.data.manager.P3.DJIProductManager.c()' on a null object reference
                                                                        at dji.midware.media.e.c.b.a(Unknown Source)
                                                                        at dji.midware.media.e.c.b.a(Unknown Source)
                                                                        at dji.sdk.camera.view.FpvLiveView.surfaceCreated(Unknown Source)
                                                                        at android.view.SurfaceView.updateWindow(SurfaceView.java:720)
                                                                        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:215)
                                                                        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1014)
                                                                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2620)
                                                                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1544)
                                                                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7613)
                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                                                                        at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                        at android.view.Choreographer.doFrame(Choreographer.java:622)
                                                                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:7409)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I have got the same crash with the FPVOverlayWidget and FPVWidget using dji ui library 4.3.2

Also with dji.sdk.camera.view.CameraLiveView

I havent connected to any drone.

ZeroCool2u commented 7 years ago

@jayakrishnan1236 @oliverou @talobin I am also having this exact some issue when following the tutorials.

ZeroCool2u commented 7 years ago

However, when I remove the FPVOverlayWidget and FPVWidget the application runs successfully.

ZeroCool2u commented 7 years ago

Okay, so upon further investigation, it looks like this only happens when you run the app and do not have the phone connected to the R/C controller.

jknair0 commented 7 years ago

No it happens when you are not registered to dji sdk. DJISDKManager#registerApp. Before you inflating the view onto screen, register with the SDK , it wont happen. However, SDK should handle this sort of situation instead of crashing. @ZeroCool2u

ZeroCool2u commented 7 years ago

@jayakrishnan1236 Oh, I suppose that makes sense why it works on my Pixel XL, but not the emulator then. The emulator does successfully register eventually, but it definitely takes longer than the physical device.

Do you have any information about how to force the registration prior to inflating the view? Do you just have to make sure that the view with the FPV widgets is not the default at launch?

jknair0 commented 6 years ago

Yes i am doing so. I am making sure that it registers in one screen an inflates in other.

ZeroCool2u commented 6 years ago

@jayakrishnan1236 Thanks for the suggestion, that's what we ended up doing as well. Later on though, we had to change the design of the app to enable usage between the different activities. We used the Google Maps example that shows how to register the SDK using the Application Class, which is not something that is typically done by most apps. However, it does seem to be the best option for apps that need SDK access in multiple activities.

talobin commented 6 years ago

Closing this issue since it should be fixed with 4.4.1. Please feel free to reopen if problem occurs again.