nullpointer exception on nativead [ getContext() or getActivity()] - Fragment

1 200 zobrazení
Preskočiť na prvú neprečítanú správu

Kush

neprečítané,
17. 3. 2017, 6:49:3417. 3. 2017
komu: Google Mobile Ads SDK Developers
Error :- when user back press from second activity to home activity. on NativeexpressAd - getContext() or getActivity()

private void addNativeExpressAds() {

        // Loop through the items array and place a new Native Express ad in every ith position in
        // the items List.
        for (int i = 0; i <= mRecyclerViewItems.size(); i += ITEMS_PER_AD) {

            // Check whether we already have a NativeExpressAdView on the list before adding one
            if( (mRecyclerViewItems.size() - i == 0) || !(mRecyclerViewItems.get(i) instanceof NativeExpressAdView)  ){
                NativeExpressAdView adView = new NativeExpressAdView(getContext()); ERROR
                mRecyclerViewItems.add(i, adView);
            }

        }
    }

E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
                                                                                    at android.view.ViewConfiguration.get(ViewConfiguration.java:389)
                                                                                    at android.view.View.<init>(View.java:4064)
                                                                                    at android.view.View.<init>(View.java:4186)
                                                                                    at android.view.ViewGroup.<init>(ViewGroup.java:591)
                                                                                    at android.view.ViewGroup.<init>(ViewGroup.java:587)
                                                                                    at android.view.ViewGroup.<init>(ViewGroup.java:583)
                                                                                    at android.view.ViewGroup.<init>(ViewGroup.java:579)
                                                                                    at com.google.android.gms.ads.BaseAdView.<init>(Unknown Source)
                                                                                    at com.google.android.gms.ads.NativeExpressAdView.<init>(Unknown Source)
                                                                                    at com.sopo.fragment.PostListFragment.addNativeExpressAds(PostListFragment.java:228)
                                                                                    at com.sopo.fragment.PostListFragment.rebuildAdapterList(PostListFragment.java:182)
                                                                                    at com.sopo.fragment.PostListFragment.access$300(PostListFragment.java:41)
                                                                                    at com.sopo.fragment.PostListFragment$1.onChildChanged(PostListFragment.java:133)
                                                                                    at com.google.android.gms.internal.zzbox.zza(Unknown Source)
                                                                                    at com.google.android.gms.internal.zzbqx.zzZS(Unknown Source)
                                                                                    at com.google.android.gms.internal.zzbra$1.run(Unknown Source)
                                                                                    at android.os.Handler.handleCallback(Handler.java:739)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                    at android.os.Looper.loop(Looper.java:148)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
code

Chris Feldman (Mobile Ads SDK Team)

neprečítané,
17. 3. 2017, 10:53:1717. 3. 2017
komu: Google Mobile Ads SDK Developers
Hi,

This does not appear to be an issue with the Mobile Ads SDK. It is your call to getContext() that is throwing the null pointer exception. This can happen for a number of reasons, and is a result of your Activity/Fragment relationship. If you'd like to send me a sample that I can build and debug directly, I can attempt to assist you further. That being said, this question might be better suited for StackOverflow.

If you do decide to send me your app, you can do so privately so it isn't public to the forum. Let me know if you have any further questions.

Regards,
Chris Feldman
Mobile Ads SDK Team

Kush Vatsa

neprečítané,
17. 3. 2017, 12:21:4517. 3. 2017
komu: google-adm...@googlegroups.com
Hello Chris, 

If you have any sample regarding abstract class - native ads with recyclerview than send me.
I am very thankful to you.

Regards


--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/Zp00oHoQx6o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Feldman (Mobile Ads SDK Team)

neprečítané,
17. 3. 2017, 16:15:2017. 3. 2017
komu: Google Mobile Ads SDK Developers
Hi,

You can view our NativeExpressRecylerViewExample on GitHub. Let me know if you have any further questions.

Regards,
Chris Feldman
Mobile Ads SDK Team

On Friday, March 17, 2017 at 12:21:45 PM UTC-4, Kush wrote:
Hello Chris, 

If you have any sample regarding abstract class - native ads with recyclerview than send me.
I am very thankful to you.

Regards

Odpovedať všetkým
Odpovedať autorovi
Poslať ďalej
0 nových správ