title: Android unfortunately app has stopped admob
body: <p>I am trying to add <code>adMob</code> ad in my android application, but it gives me unfortunately stopped error,</p>
  
  <p>I am not expert in android program so dont know whats wrong in aap.</p>
  
  <p>below is my <code>MainActivity, adview, and manifest</code></p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>package com.nyt.ilm.ilmsarf;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.google.android.gms.ads.AdRequest;
  import com.google.android.gms.ads.AdView;
  import com.nyt.ilm.ilmsarf.P1.OnFragmentInteractionListener;
  
  import android.content.Context;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v4.view.ViewPager.LayoutParams;
  import android.view.ViewTreeObserver;
  import android.widget.ListView;
  import android.widget.RelativeLayout;
  
  
  public class MainActivity extends FragmentActivity implements
          OnFragmentInteractionListener {
  
      ViewPager viewpager;
      Context mContext=MainActivity.this; 
      SharedPreferences appPreferences; 
      boolean isAppInstalled = false; 
       /* Your ad unit id. Replace with your actual ad unit id. */
       public boolean adViewHeightSet = false;
          @Override
      protected void onCreate(Bundle arg0) {
          // TODO Auto-generated method stub
          super.onCreate(arg0);
  
          appPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
          isAppInstalled = appPreferences.getBoolean("isAppInstalled",false); 
          if(isAppInstalled==false){ 
                 // add shortcutIcon code here
              Intent shortcutIntent = new Intent(getApplicationContext(),
                      MainActivity.class);
  
              shortcutIntent.setAction(Intent.ACTION_MAIN);
              //shortcutIntent is added with addIntent
              Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
              addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "IlmSarf");
              addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                  Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                              R.drawable.ic_launcher));
  
              addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
              // finally broadcast the new Intent
              getApplicationContext().sendBroadcast(addIntent);
              // finally isAppInstalled should be true. 
          SharedPreferences.Editor editor = appPreferences.edit(); 
          editor.putBoolean("isAppInstalled", true); 
          editor.commit(); 
          }
  
          setContentView(R.layout.activity_main);
          viewpager = (ViewPager) findViewById(R.id.pager);
          FragmentPagerAdapter fm = new MyPageAdapter(getSupportFragmentManager());
          viewpager.setAdapter(fm);
          viewpager.setCurrentItem(fm.getCount() - 1);
  
          //// Ad Banner
  
          AdView adView = (AdView)this.findViewById(R.id.adView);
          AdRequest adRequest = new AdRequest.Builder().build();
          adView.loadAd(adRequest);
  
          adView.getViewTreeObserver().addOnGlobalLayoutListener(
          new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  if (adViewHeightSet) return;
  
                  AdView adView = (AdView) findViewById(R.id.adView);             
  
                  ListView list = (ListView) findViewById(R.id.list);                
  
                  RelativeLayout.LayoutParams params = 
                  new RelativeLayout.LayoutParams(
                          LayoutParams.MATCH_PARENT,      
                          LayoutParams.MATCH_PARENT
                  );
  
                  params.setMargins(0, 0, 0,   adView.getHeight()+ 15);
  
                  list.setLayoutParams(params);
                  adViewHeightSet = true;
              }
          });
  
  
      }
  
      @Override
      public void onFragmentInteraction(Uri uri) {
          // TODO Auto-generated method stub
  
      }
  
  }
  
  class MyPageAdapter extends FragmentPagerAdapter {
  private List&lt;Fragment&gt; fragments;
      public MyPageAdapter(FragmentManager fm) {
          super(fm);
          // TODO Auto-generated constructor stub
          this.fragments = new ArrayList&lt;Fragment&gt;();
          fragments.add(new P1());
          fragments.add(new P2());
          fragments.add(new P3());  
  
      }
  
      @Override
      public Fragment getItem(int position) {
          // TODO Auto-generated method stub
          return fragments.get(position);
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return fragments.size();
      }
  
  }
  </code></pre>
  
  <p><strong>adview.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;com.google.android.gms.ads.AdView
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:id="@+id/adView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          ads:adSize="SMART_BANNER"
          ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/&gt;
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:divider="@null"
          android:dividerHeight="0dp"&gt;
      &lt;/ListView&gt;    
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Manifest</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest package="com.nyt.ilm.ilmsarf"
      android:versionCode="3"
      android:versionName="1.3" xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="19" /&gt;
      &lt;uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/&gt;
      &lt;uses-permission android:name='com.android.launcher.permission.UNINSTALL_SHORTCUT'/&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;meta-data android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version"/&gt;
      &lt;activity android:label="@string/app_name" android:name="adview"&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.nyt.ilm.ilmsarf.MainActivity"
               android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"&gt;
              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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>here is the logcat</strong></p>
  
  <pre><code>06-19 17:19:05.452: I/Process(1144): Sending signal. PID: 1144 SIG: 9
  06-19 17:19:49.687: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.687: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.687: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.687: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.687: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.687: D/jdwp(1237): sendBufferedRequest : len=0x41
  06-19 17:19:49.698: D/dalvikvm(1237): open_cached_dex_file : /data/app/com.nyt.ilm.ilmsarf-1.apk /data/dalvik-cache/data@app@com.nyt.ilm.ilmsarf-1.apk@classes.dex
  06-19 17:19:49.699: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.699: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.699: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.699: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.705: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.705: W/Trace(1237): Unexpected value from nativeGetEnabledTags: 0
  06-19 17:19:49.706: D/dalvikvm(1237): create interp thread : stack size=32KB
  06-19 17:19:49.706: D/dalvikvm(1237): create new thread
  06-19 17:19:49.706: D/dalvikvm(1237): new thread created
  06-19 17:19:49.706: D/dalvikvm(1237): update thread list
  06-19 17:19:49.706: D/dalvikvm(1237): threadid=11: interp stack at 0x5d824000
  06-19 17:19:49.706: D/dalvikvm(1237): threadid=11: created from interp
  06-19 17:19:49.706: D/dalvikvm(1237): start new thread
  06-19 17:19:49.706: D/dalvikvm(1237): threadid=11: notify debugger
  06-19 17:19:49.706: D/dalvikvm(1237): threadid=11 (SharedPreferencesImpl-load): calling run()
  06-19 17:19:49.709: D/dalvikvm(1237): threadid=11: exiting
  06-19 17:19:49.709: D/dalvikvm(1237): threadid=11: bye!
  06-19 17:19:49.721: D/skia(1237): Flag is not 10
  06-19 17:19:49.726: D/skia(1237): Flag is not 10
  06-19 17:19:49.736: D/skia(1237): Flag is not 10
  06-19 17:19:49.762: D/AndroidRuntime(1237): Shutting down VM
  06-19 17:19:49.763: W/dalvikvm(1237): threadid=1: thread exiting with uncaught exception (group=0x40f829a8)
  06-19 17:19:49.766: E/AndroidRuntime(1237): FATAL EXCEPTION: main
  06-19 17:19:49.766: E/AndroidRuntime(1237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyt.ilm.ilmsarf/com.nyt.ilm.ilmsarf.MainActivity}: java.lang.NullPointerException
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread.access$600(ActivityThread.java:156)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.os.Handler.dispatchMessage(Handler.java:99)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.os.Looper.loop(Looper.java:153)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread.main(ActivityThread.java:5297)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invoke(Method.java:511)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at dalvik.system.NativeStart.main(Native Method)
  06-19 17:19:49.766: E/AndroidRuntime(1237): Caused by: java.lang.NullPointerException
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at com.nyt.ilm.ilmsarf.MainActivity.onCreate(MainActivity.java:76)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.Activity.performCreate(Activity.java:5122)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
  06-19 17:19:49.766: E/AndroidRuntime(1237):     ... 11 more
  06-19 17:19:49.777: D/dalvikvm(1237): GC_CONCURRENT freed 287K, 4% free 9187K/9500K, paused 1ms+2ms, total 20ms
  </code></pre>
  
  <p>Please help.</p>
  
  <p>Thanks in advance.</p>