Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

java.lang.NullPointerException inside initLayoutForFingerprint #172

Open
Vojtas87 opened this issue May 7, 2018 · 8 comments
Open

java.lang.NullPointerException inside initLayoutForFingerprint #172

Vojtas87 opened this issue May 7, 2018 · 8 comments

Comments

@Vojtas87
Copy link

Vojtas87 commented May 7, 2018

Hello,

I received this crash report in my app (Android 8.0, Xperia XA1 (G3121)):

`java.lang.NullPointerException
com.github.omadahealth.lollipin.lib.managers.AppLockActivity.initLayoutForFingerprint

java.lang.RuntimeException: Unable to resume activity {CustomPinActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.hardware.fingerprint.FingerprintManager.isHardwareDetected()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3754)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3794)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2980)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1663)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:206)
at android.app.ActivityThread.main(ActivityThread.java:6749)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.hardware.fingerprint.FingerprintManager.isHardwareDetected()' on a null object reference
at com.github.omadahealth.lollipin.lib.managers.AppLockActivity.initLayoutForFingerprint(AppLockActivity.java:147)
at com.github.omadahealth.lollipin.lib.managers.AppLockActivity.onResume(AppLockActivity.java:84)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
at android.app.Activity.performResume(Activity.java:7089)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3724)
... 10 more`

Could you take a look at this, please?

Thank you in advance.

@norrisboat
Copy link

@Vojtas87 make sure your activity extends PinActivity not your custom pin activity

@Vojtas87
Copy link
Author

@norrisboat Yes, it does. My main activity (only this activity) extends PinCompatActivity.

@smsrobot
Copy link

smsrobot commented Jun 4, 2018

I have same problem with my app, on Sony devices with android 8.0+ I am always getting this error in my error log, my activity extends "AppLockActivity".
It looks like "mFingerprintManager" is null in function initLayoutForFingerprint.

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.hardware.fingerprint.FingerprintManager.isHardwareDetected()' on a null object reference
at com.github.omadahealth.lollipin.lib.managers.AppLockActivity.initLayoutForFingerprint(AppLockActivity.java:147)
at com.github.omadahealth.lollipin.lib.managers.AppLockActivity.onResume(AppLockActivity.java:84)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
at android.app.Activity.performResume(Activity.java:7089)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3724)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3794)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2980)
at android.app.ActivityThread.-wrap11(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1663)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:206)
at android.app.ActivityThread.main(ActivityThread.java:6749)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)

@smsrobot
Copy link

smsrobot commented Jun 5, 2018

This is forced solution for those who are using "AppLockActivity" as base class.
Extend your lock activity from this class, it has additional exception handling for null pointer exception, it will prevent you app from crashing - affected users will have fingerprint UI hidden.

public abstract class MyAppLockActivity extends AppLockActivity {

@Override
protected void onResume() {
    super.onResume();
    //Init layout for Fingerprint
    myInitLayoutForFingerprint();
}

/**
 * Init {@link FingerprintManager} of the {@link android.os.Build.VERSION#SDK_INT} is > to Marshmallow
 * and {@link FingerprintManager#isHardwareDetected()}.
 */
private void myInitLayoutForFingerprint() {
    mFingerprintImageView = (ImageView) this.findViewById(R.id.pin_code_fingerprint_imageview);
    mFingerprintTextView = (TextView) this.findViewById(R.id.pin_code_fingerprint_textview);
    if (mType == AppLock.UNLOCK_PIN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mFingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);
        mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManager).build(mFingerprintImageView, mFingerprintTextView, this);
        try {
            if (mFingerprintManager.isHardwareDetected() && mFingerprintUiHelper.isFingerprintAuthAvailable()
                    && mLockManager.getAppLock().isFingerprintAuthEnabled()) {
                mFingerprintImageView.setVisibility(View.VISIBLE);
                mFingerprintTextView.setVisibility(View.VISIBLE);
                mFingerprintUiHelper.startListening();
            } else {
                mFingerprintImageView.setVisibility(View.GONE);
                mFingerprintTextView.setVisibility(View.GONE);
            }
        } catch (SecurityException e) {
            Log.e(TAG, e.toString());
            mFingerprintImageView.setVisibility(View.GONE);
            mFingerprintTextView.setVisibility(View.GONE);
        } catch (Exception e) {
            Log.e(TAG, e.toString());
            mFingerprintImageView.setVisibility(View.GONE);
            mFingerprintTextView.setVisibility(View.GONE);
        }
    } else {
        mFingerprintImageView.setVisibility(View.GONE);
        mFingerprintTextView.setVisibility(View.GONE);
    }
}

}

@Vojtas87
Copy link
Author

@smsrobot Thanks. I will try your solution and I hope it will help my users. :-) Also I'm handling with another crash. Do you have some advice too, please? #184

@miralas
Copy link

miralas commented Sep 10, 2018

@smsrobot I have same issue. My custom activity already extends AppLockActivity and uses your code example, but nothing! Android 8.0+ still crashing. :(

@anton-piliugin
Copy link

anton-piliugin commented Sep 19, 2018

@smsrobot I have same issue. My custom activity already extends AppLockActivity and uses your code example, but nothing! Android 8.0+ still crashing. :(

Added some tips on how to fix:
#184 (comment)

@miralas
Copy link

miralas commented Oct 10, 2018

@anton-piliugin yeah, thx, your solution works perfectly!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants