googleads / googleads-consent-sdk-ios

Consent SDK
https://developers.google.com/admob/ios/eu-consent
Apache License 2.0
31 stars 47 forks source link

NullPointerException in production #22

Closed yccheok closed 6 years ago

yccheok commented 6 years ago

I get a few NullPointerException crash report in production.

Samsung Galaxy S8 (dreamlte), 4096MB RAM, Android 8.0
Report 1 of 1
java.lang.NullPointerException: 

  at android.app.Dialog.<init> (Dialog.java:209)

  at android.app.Dialog.<init> (Dialog.java:194)

  at com.google.ads.consent.ConsentForm.<init> (ConsentForm.java:77)

  at com.google.ads.consent.ConsentForm.<init> (ConsentForm.java:46)

  at com.google.ads.consent.ConsentForm$Builder.build (ConsentForm.java:210)

  at org.yccheok.jstock.gui.WatchlistFragment.showConsentForm (WatchlistFragment.java:1997)

Any idea why such happen. My code to show consent form is as follow. I'm using

implementation 'com.google.android.ads.consent:consent-library:1.0.4'
    private void showConsentForm() {
        if (this.consentFormHolder != null) {
            return;
        }

        URL privacyUrl = null;
        try {
            privacyUrl = new URL(org.yccheok.jstock.network.Utils.getURL(org.yccheok.jstock.network.Utils.Type.PRIVACY_POLICY));
        } catch (MalformedURLException e) {
            Log.e(TAG, "", e);
        }

        this.consentFormHolder = new ConsentFormHolder();

        consentFormHolder.consentForm = new ConsentForm.Builder(getContext(), privacyUrl)
                .withListener(new ConsentFormListener() {
                    @Override
                    public void onConsentFormLoaded() {
                        // Consent form loaded successfully.
                        consentFormHolder.consentForm.show();
                    }

                    @Override
                    public void onConsentFormOpened() {
                        // Consent form was displayed.
                    }

                    @Override
                    public void onConsentFormClosed(
                            ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                        consentFormHolder = null;

                        if (consentStatus == ConsentStatus.PERSONALIZED) {
                            ConsentInformation.getInstance(getContext())
                                    .setConsentStatus(consentStatus);

                            displayAdMob(false);

                            org.yccheok.jstock.gui.Utils.trackEvent(TAG, "showConsentForm", "personalized");
                        } else if (consentStatus == ConsentStatus.NON_PERSONALIZED) {
                            ConsentInformation.getInstance(getContext())
                                    .setConsentStatus(consentStatus);

                            displayAdMob(true);

                            org.yccheok.jstock.gui.Utils.trackEvent(TAG, "showConsentForm", "non_personalized");
                        } else if (userPrefersAdFree) {
                            ((JStockFragmentActivity)getActivity()).shop();

                            org.yccheok.jstock.gui.Utils.trackEvent(TAG, "showConsentForm", "shop");
                        } else {
                            displayAdMob(false);

                            org.yccheok.jstock.gui.Utils.trackEvent(TAG, "showConsentForm", "unknown");
                        }

                    }

                    @Override
                    public void onConsentFormError(String errorDescription) {
                        consentFormHolder = null;
                        displayAdMob(false);
                    }
                })
                .withPersonalizedAdsOption()
                .withNonPersonalizedAdsOption()
                .withAdFreeOption()
                .build();           <--- Line 1997

        consentFormHolder.consentForm.load();
    }
rampara commented 6 years ago

@yccheok can you open an issue on the Android specific repository for the Consent SDK.