title: AdMob app keeps crashing
body: <p>My Code:
  Java:</p>
  
  <pre><code>import android.os.Bundle;
  import android.app.Activity;
  import android.util.AttributeSet;
  import android.view.Gravity;
  import android.view.Menu;
  import android.widget.LinearLayout;
  
  import com.google.ads.AdRequest;
  import com.google.ads.AdSize;
  import com.google.ads.AdView;
  
  public class MainActivity extends Activity
  {
  
  private AdView adView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      adView = (AdView) findViewById(R.id.adView);
  
      AdRequest request = new AdRequest();
      request.setTesting(true);
      adView.loadAd(request);
  
  }
  
  @Override
  protected void onDestroy()
  {
      super.onDestroy();
      if(adView!=null) adView.destroy();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  }
  </code></pre>
  
  <p>xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/linearlayout"
      android:orientation="vertical"&gt;
  
  &lt;com.google.ads.AdView
          android:id="@+id/adView"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          ads:adUnitId="MY_UNIT_ID"
          ads:adSize="BANNER"
          ads:testDevices = "MY_TEST_DEVICE"
          android:layout_gravity="bottom"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="...."
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="10"
      android:targetSdkVersion="16" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com....MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name="com.google.ads.AdActivity"
                android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/&gt;
  &lt;/application&gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>It just keeps crashing on my testing device in this line:  setContentView(R.layout.activity_main);
  The App isnt published in the Play Store, because i want to test it first.
  So the error should be in the xml. I hope you can help me.</p>
  
  <p>EDIT: logcat:</p>
  
  <pre><code>06-19 19:47:25.968  19697-19697/?                              E/AndroidRuntime: FATAL     EXCEPTION: main
      java.lang.NoClassDefFoundError: com.google.ads.AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:24)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      06-19 19:47:54.379  20244-20244/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com.google.ads.AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:24)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      06-19 19:49:34.906  20657-20657/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com.google.ads.AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:24)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      06-19 19:50:20.925  21220-21220/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com/google/ads/AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:24)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      Caused by: java.lang.ClassNotFoundException: Didn't find class   "com.google.ads.AdView" on path: /data/app/com.stefan.game-2.apk
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
      ... 15 more
      06-19 19:52:36.770  22087-22087/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com/google/ads/AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:25)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.stefan.game-1.apk
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
      ... 15 more
      06-19 20:02:56.041  23603-23603/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com/google/ads/AdView
      at com.stefan.game.MainActivity.onCreate(MainActivity.java:26)
      at android.app.Activity.performCreate(Activity.java:5104)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
      at android.app.ActivityThread.access$600(ActivityThread.java:141)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:5041)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      at dalvik.system.NativeStart.main(Native Method)
      Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.stefan.game-2.apk
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
      ... 15 more
      06-19 20:04:33.134  24855-24855/?                              E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com/google/ads/AdView
  </code></pre>
  
  <p>EDIT 2: I got it working by reading this: <a href="https://stackoverflow.com/questions/16649586/android-studio-error-inflating-class-com-google-ads-adview">Android Studio - Error inflating class com.google.ads.AdView</a> and doing gradlew clean in terminal and clicking Build -> Rebuild Project. Thanks for the help!</p>