0

I followed this tutorial on how to add AdView

https://developers.google.com/mobile-ads-sdk/docs/

By adding this to my AndroidManifest.xml :

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

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

<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|sm    allestScreenSize"/>

And this to build.gradle

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
}

And to my java file:

import com.google.android.gms.ads.*;


public class admob extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.admoblayout);


    // Create an ad.
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("My_UnitID_Here");

    RelativeLayout layout = (RelativeLayout) findViewById(R.layout.admoblayout);
    layout.addView(adView);


    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
}

}

But whenever I open the activity it crashes

logcat:

FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView

user2989698
  • 81
  • 1
  • 10

1 Answers1

0

Sometime when adding new layouts or even modifying an existing layout, IDE requires the refresh of the project for it to take affect.

Once you refresh/rebuild the project you should be good to go.

SearchForKnowledge
  • 3,613
  • 8
  • 45
  • 115