Credntia / MVBarcodeReader

A Barcode scanner library for Android. Uses the Google Play Services' mobile vision api for barcode detection.
Apache License 2.0
68 stars 22 forks source link

NullPointerException on scan fragment #35

Open Yennefer opened 6 years ago

Yennefer commented 6 years ago

Hi! I'm using your BarcodeCaptureFragment in my main Activity and from time to time I'm getting a NullPointerException.

Steps to reproduce:

  1. Open activity with BarcodeCaptureFragment
  2. Quickly send app to background by clicking home button on the device, before you can see frame with the camera on the Activity (so I'm guessing this is happening when BarcodeCaptureFragment wasn't initialised yet or was in the middle of initialization)
  3. Return the app from the background.

Full logs from Logcat:

04-12 10:14:54.936 25817-25817/? I/art: Late-enabling -Xcheck:jni
04-12 10:14:55.459 25817-25817/com.maghelyen.vegcode W/System: ClassLoader referenced unknown path: /data/app/com.maghelyen.vegcode-1/lib/arm
04-12 10:14:56.067 25817-25817/com.maghelyen.vegcode I/InstantRun: starting instant run server: is main process
04-12 10:14:56.212 25817-25817/com.maghelyen.vegcode W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-12 10:14:56.249 25817-25834/com.maghelyen.vegcode D/NetworkSecurityConfig: No Network Security Config specified, using platform default
04-12 10:14:56.382 25817-25841/com.maghelyen.vegcode D/ApplicationLoaders: ignored Vulkan layer search path /data/app/com.google.android.gms-2/lib/arm:/system/fake-libs:/data/app/com.google.android.gms-2/base.apk!/lib/armeabi-v7a for namespace 0xae27d090
04-12 10:14:56.511 25817-25817/com.maghelyen.vegcode W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite not found.
04-12 10:14:56.535 25817-25817/com.maghelyen.vegcode I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite:0 and remote module com.google.android.gms.vision.dynamite:1702
04-12 10:14:56.535 25817-25817/com.maghelyen.vegcode I/DynamiteModule: Selected remote version of com.google.android.gms.vision.dynamite, version >= 1702
04-12 10:14:56.545 25817-25817/com.maghelyen.vegcode W/System: ClassLoader referenced unknown path: 
04-12 10:14:56.546 25817-25817/com.maghelyen.vegcode D/ApplicationLoaders: ignored Vulkan layer search path /data/app/com.google.android.gms-2/lib/arm:/system/fake-libs:/data/app/com.google.android.gms-2/base.apk!/lib/armeabi-v7a for namespace 0xae27d0d0
04-12 10:14:56.570 25817-25817/com.maghelyen.vegcode W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004b/n/armeabi-v7a
04-12 10:14:56.570 25817-25817/com.maghelyen.vegcode W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004b/n/armeabi
04-12 10:14:56.617 25817-25817/com.maghelyen.vegcode I/Vision: Loading library libbarhopper.so
04-12 10:14:56.642 25817-25817/com.maghelyen.vegcode W/linker: /data/data/com.google.android.gms/app_vision/barcode/libs/armeabi-v7a/libbarhopper.so: unused DT entry: type 0x7ffffffd arg 0x76d
04-12 10:14:56.643 25817-25817/com.maghelyen.vegcode I/Vision: libbarhopper.so library load status: true
04-12 10:14:56.653 25817-25817/com.maghelyen.vegcode I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
04-12 10:14:56.653 25817-25817/com.maghelyen.vegcode I/DynamiteModule: Selected local version of com.google.android.gms.flags
04-12 10:14:56.690 25817-25817/com.maghelyen.vegcode D/SCANNER-FRAGMENT: created camera source
04-12 10:14:56.966 25817-25817/com.maghelyen.vegcode W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
04-12 10:14:57.572 25817-25817/com.maghelyen.vegcode D/CameraSourcePreview: Configuration changed
04-12 10:14:57.573 25817-25817/com.maghelyen.vegcode D/AndroidRuntime: Shutting down VM
04-12 10:14:57.799 25817-25817/com.maghelyen.vegcode E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.maghelyen.vegcode, PID: 25817
                                                                       java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.common.images.Size.getWidth()' on a null object reference
                                                                           at online.devliving.mobilevisionpipeline.camera.CameraSourcePreview.updateOverlay(CameraSourcePreview.java:109)
                                                                           at online.devliving.mobilevisionpipeline.camera.CameraSourcePreview.onConfigurationChanged(CameraSourcePreview.java:153)
                                                                           at android.view.View.dispatchConfigurationChanged(View.java:10498)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1312)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1316)
                                                                           at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:3341)
                                                                           at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1771)
                                                                           at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
                                                                           at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:621)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
                                                                           at android.os.Handler.handleCallback(Handler.java:751)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
04-12 10:14:58.656 25817-25845/com.maghelyen.vegcode I/CrashlyticsCore: Crashlytics report upload complete: 5ACF0770001F-0001-64D9-BC2DC6667164

Can you help me figure out what may cause this exception? My Activity code:

class ScanActivity : BaseActivity(), ScanContract.View {

    @Inject lateinit var presenter : ScanContract.Presenter

    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)

        (application as VegCodeApplication).appComponent.newScanComponent().inject(this)
        presenter.attach(this)

        setContentView(R.layout.activity_scan)
        initBarcodeFragment()
    }

    override fun onDestroy() {
        super.onDestroy()
        presenter.detach()
    }

    override fun initBarcodeFragment() {
        val fragment = BarcodeCaptureFragment.instantiate(SINGLE_AUTO)
        fragment.setListener(presenter.getScanListener())
        supportFragmentManager.beginTransaction()
                .add(R.id.scan_fragment, fragment)
                .commit()
    }
}

Activity xml:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.maghelyen.vegcode.ui.scan.ScanActivity">

    <FrameLayout
        android:id="@+id/scan_fragment"
        android:layout_width="match_parent"
        android:layout_height="@dimen/scan_fragment_height"
        android:layout_marginEnd="@dimen/big_margin"
        android:layout_marginStart="@dimen/big_margin"
        android:layout_marginTop="@dimen/big_margin"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/big_margin"
        android:layout_marginStart="@dimen/big_margin"
        android:layout_marginTop="@dimen/big_margin"
        android:gravity="center"
        android:text="@string/scan_bar_code_text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scan_fragment" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scan_fragment" />
</android.support.constraint.ConstraintLayout>