Skip to content

App crashes with NullPointerException on Android 13 (mPreviewView / mLeaderControls null) #24

Description

@moeinimani

Device / OS:

  • Redmi Note 10 Pro
  • Android 13, MIUI 14

Package: com.googleresearch.capturesync

Issue:
The app crashes immediately after being resumed (crash loop) with a NullPointerException. Logcat shows the crash happens in MainActivity.onResume() at line 320, when the code calls getHolder() on an AutoFitSurfaceView instance that is still null at that point.

Full stack trace:
07-24 12:57:07.817 13097 13097 E AndroidRuntime: FATAL EXCEPTION: main

07-24 12:57:07.817 13097 13097 E AndroidRuntime: Process: com.googleresearch.capturesync, PID: 13097

07-24 12:57:07.817 13097 13097 E AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {com.googleresearch.capturesync/com.googleresearch.capturesync.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.view.SurfaceHolder com.googleresearch.capturesync.AutoFitSurfaceView.getHolder()’ on a null object reference

at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4988)

at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5021)

at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)

at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)

at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2394)

at android.os.Handler.dispatchMessage(Handler.java:106)

at android.os.Looper.loopOnce(Looper.java:211)

at android.os.Looper.loop(Looper.java:300)

at android.app.ActivityThread.main(ActivityThread.java:8296)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.view.SurfaceHolder com.googleresearch.capturesync.AutoFitSurfaceView.getHolder()’ on a null object reference

at com.googleresearch.capturesync.MainActivity.onResume(MainActivity.java:320)

at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1585)

at android.app.Activity.performResume(Activity.java:8675)

at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4978)

… 13 more

Steps to reproduce:

Install the APK on a device running Android 12+ (tested on Android 13 / MIUI 14).
Grant camera permission when prompted.
Open the app.
App crashes almost immediately when onResume() is called (crash loop).

Suspected cause:

In MainActivity.onResume() (line 320), the code calls mPreviewView.getHolder(), but mPreviewView (an AutoFitSurfaceView) appears to not be initialized yet at this point in the lifecycle. This likely worked on older Android versions where SurfaceView initialization/callback timing relative to onResume() was different, but breaks on newer Android versions.

Suggestion:

Add a null-check for mPreviewView before calling getHolder() in onResume(), or move the surface-dependent logic to a point in the lifecycle where the view is guaranteed to be initialized (e.g. inside a SurfaceHolder.Callback.surfaceCreated() or after onWindowFocusChanged()).

Happy to test a patch if someone points me to the right fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions