Error NullPointerException (Banner Ads)when running on tablets

135 views
Skip to first unread message

WEYE Studio

unread,
Nov 12, 2014, 4:57:26 AM11/12/14
to google-adm...@googlegroups.com
Hi,
I develop app and put admob banner ads in it by xml code. App run good on almost all phones but when running on tablets (Nexus 10, FonePad 7, Galaxy Tab 3...), it issue error NullPointerException when open app.
App run good on Nexus 7. So I don't know what error?
I have xml file activity_main.xml. Content of it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/res-auto">
    <RelativeLayout android:orientation="vertical" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="0.0dip" android:layout_weight="0.31">
        <ImageView android:id="@+id/mage" android:layout_width="match_parent" android:layout_height="match_parent" />
    </RelativeLayout>
  <com.google.android.gms.ads.AdView 
      android:id="@+id/adView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ads:adSize="SMART_BANNER"
      ads:adUnitId="my unit ad id"/> 
</LinearLayout>
 
 And this is java code:

protected void onCreate(Bundle var1) {
      super.onCreate(var1);
      this.setContentView(R.layout.activity_main);
 
AdView adView = (AdView)this.findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder()
      .build();
      adView.loadAd(adRequest);
} 
 
Logcast in eclipse show error at adView.loadAd.
Have method to fix it?
Please help me!!!
Thanks

William Ferguson

unread,
Nov 12, 2014, 10:40:00 AM11/12/14
to google-adm...@googlegroups.com
Posting the stacktrace would help. And this is probably better asked on StackOverflow.

If your stacktrace goes no deeper than adView.loadAd() then it means AdVIew is undefined. Your XML and code appear fine, and since this only happens on tablets I suspect that your have defined a tablet specific layout that doesn't contain the AdView.

William

WEYE Studio

unread,
Nov 12, 2014, 11:49:30 PM11/12/14
to google-adm...@googlegroups.com
Thank you! 
I had important error and i fixed it. I added activity_main.xml to folders: layout-sw600dp and layout-sw720dp. Before I missed this :)

Vào 22:40:00 UTC+7 Thứ tư, ngày 12 tháng mười một năm 2014, William Ferguson đã viết:

William Ferguson

unread,
Nov 13, 2014, 12:19:33 AM11/13/14
to google-adm...@googlegroups.com

Glad I could help :)

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/RG8W51t5ccc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages