Android LicenseChecker crashes with null pointer exception

android, crash

Solution

I modified the method LicenseValidator.verify(), adding a protection check at the begining:

public void verify(PublicKey publicKey, int responseCode, String signedData, String signature) {
    if (signedData==null){
        handleInvalidResponse();
        return;
    }
    ...
}

Problem

It seems that if an Android phone is not logged in to Google Play, a checkAccess-call will throw a NullPointerException and eventually crash the application: ``` // user not logged in to Google Play LicenseChecker licenseChecker = new LicenseChecker(...); licenseChecker.checkAccess(...) // throws a nullpointer exception and crasches the app ``` The NullPointerException happens deep inside the Android framework in a separate thread: ``` FATAL EXCEPTION: background thread java.lang.NullPointerException com.google.android.vending.licensing.LicenseValidator.verify() ``` hence there seems no way for the application to catch it and avoid the crash. Any ideas how to avoid this crash? (t should be a legal situation not to be logged into Google Play) The only way I can think of is to check Google Play login status prior to invoking checkAccess.

Original source