Skip to content

[Bug report] Null Pointer Exception while using ML Kit #565

@Prachi-Jamdade

Description

@Prachi-Jamdade

ML Kit is not working if I created product flavors
ML Kit stoppped working after I created product flavors in my android application. I am using ML Kit for text recognition in my app. Everything was fine until I created product flavors.

The first error message I got was this -

java.lang.IllegalStateException: MlKitContext has not been initialized

Below code is to use content provider to initialize Ml Kit manually in Manifest file.

<provider android:name="com.google.mlkit.common.internal.MlKitInitProvider" android:authorities="${applicationId}.mlkitinitprovider" android:enabled="true" android:exported="false"/>

Getting following error message after initializing ML Kit manually -

Attempt to invoke virtual method 'void com.google.android.gms.internal.mlkit_vision_common.zzcq.zza(com.google.android.gms.internal.mlkit_vision_common.zzcq$zza, com.google.android.gms.internal.mlkit_vision_common.zzag)' on a null object reference

Below is the code I used for text recognition-

            val image = InputImage.fromBitmap(bitmapNew, 0)
            val recognizer = TextRecognition.getClient()
            val res = recognizer.process(image)
                .addOnSuccessListener { visionText ->
                    result = visionText.text
                }
                .addOnFailureListener{ e ->

                }

Metadata

Metadata

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