0

I had an xml layout which worked fine, but I have tried the AdMob ads inserting an AdView and it isn't working anymore. In the log I can just see the "before" text, but I can't see the "after" text. What could this be due to?

fragment_home.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:stretchColumns="*" >

       <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >

            //Stuff...

        </TableRow>

       <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >

            //Stuff...

        </TableRow>

       <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >

            //Stuff...

        </TableRow>

        <com.google.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            android:id="@+id/adView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="ca-app-pub-0771856019955508/3441120220"
            ads:adSize="BANNER" />

</TableLayout>  

HomeFragment.java

public class HomeFragment extends Fragment {

    private View rootView;
    private AdView adview1;
    private AdRequest adRequest;

    public HomeFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        Log.e("Et_ad","before");
        rootView = inflater.inflate(R.layout.fragment_home, container, false);
        Log.e("Et_ad","after");

        //Stuff...

        adview1 = (AdView)rootView.findViewById(R.id.adView1);
        Log.e("Et_ad","adview1");
        adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice("TEST_DEVICE_ID")
                    .build();        
        Log.e("Et_ad","before load adview1");
        adview1.loadAd(adRequest);

        return rootView;
    }
user1903
  • 790
  • 1
  • 6
  • 10
  • Perhaps because your AdView is not within a TableRow? If there any exception in the log? – William Jul 12 '14 at 09:32
  • So maybe I should try a LinearLayout with a TableLayout and the adView inside? I'll try that later and say something about it – user1903 Jul 12 '14 at 09:33
  • Ok, I've changed that just in case; I'm pretty sure that `adview1.loadAd(adRequest);` is what is making my app crash; any help? – user1903 Jul 13 '14 at 10:12

1 Answers1

0

The problem was I pasted these lines:

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />

outside <application> ... </application>

So, it should be:

<application>
    ...
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
    ...
</application>
user1903
  • 790
  • 1
  • 6
  • 10