Admob马上崩溃

时间:2014-01-26 23:17:44

标签: java android admob

我正在尝试将admob放在我新创建的应用上。我是用XML做的。这是我的XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back1"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
  <com.google.android.gms.ads.AdView 
      android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      ads:adUnitId="ca-app-pub-4994556056318402/2453336176"
      ads:adSize="BANNER"
      ads:loadAdOnCreate="true"/>

这是java

super.onCreate(savedInstanceState);
        AdView adView = (AdView)findViewById(R.id.adView); //ads
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

和logcat:

01-26 17:50:42.392: D/dalvikvm(12060): GC_FOR_ALLOC freed 71K, 2% free 8906K/9016K, paused 15ms, total 15ms
01-26 17:50:42.392: I/dalvikvm-heap(12060): Grow heap (frag case) to 9.732MB for 1048592-byte allocation
01-26 17:50:42.408: D/dalvikvm(12060): GC_FOR_ALLOC freed <1K, 2% free 9930K/10044K, paused 13ms, total 13ms
01-26 17:50:42.454: D/AndroidRuntime(12060): Shutting down VM
01-26 17:50:42.454: W/dalvikvm(12060): threadid=1: thread exiting with uncaught exception (group=0x4160a700)
01-26 17:50:42.454: E/AndroidRuntime(12060): FATAL EXCEPTION: main
01-26 17:50:42.454: E/AndroidRuntime(12060): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.doritofacestudios.doritofacemath/com.doritofacestudios.doritofacemath.MainActivity}: java.lang.NullPointerException
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.os.Looper.loop(Looper.java:137)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread.main(ActivityThread.java:5103)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at java.lang.reflect.Method.invoke(Method.java:525)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at dalvik.system.NativeStart.main(Native Method)
01-26 17:50:42.454: E/AndroidRuntime(12060): Caused by: java.lang.NullPointerException
01-26 17:50:42.454: E/AndroidRuntime(12060):    at com.doritofacestudios.doritofacemath.MainActivity.onCreate(MainActivity.java:36)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.Activity.performCreate(Activity.java:5133)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-26 17:50:42.454: E/AndroidRuntime(12060):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-26 17:50:42.454: E/AndroidRuntime(12060):    ... 11 more
01-26 17:54:00.033: D/dalvikvm(12363): GC_FOR_ALLOC freed 30K, 1% free 8903K/8972K, paused 23ms, total 23ms
01-26 17:54:00.033: I/dalvikvm-heap(12363): Grow heap (frag case) to 9.729MB for 1048592-byte allocation
01-26 17:54:00.056: D/dalvikvm(12363): GC_FOR_ALLOC freed <1K, 1% free 9927K/10000K, paused 12ms, total 12ms
01-26 17:54:00.118: D/AndroidRuntime(12363): Shutting down VM
01-26 17:54:00.118: W/dalvikvm(12363): threadid=1: thread exiting with uncaught exception (group=0x4160a700)
01-26 17:54:00.126: E/AndroidRuntime(12363): FATAL EXCEPTION: main
01-26 17:54:00.126: E/AndroidRuntime(12363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.doritofacestudios.doritofacemath/com.doritofacestudios.doritofacemath.MainActivity}: java.lang.NullPointerException
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.os.Looper.loop(Looper.java:137)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread.main(ActivityThread.java:5103)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at java.lang.reflect.Method.invoke(Method.java:525)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at dalvik.system.NativeStart.main(Native Method)
01-26 17:54:00.126: E/AndroidRuntime(12363): Caused by: java.lang.NullPointerException
01-26 17:54:00.126: E/AndroidRuntime(12363):    at com.doritofacestudios.doritofacemath.MainActivity.onCreate(MainActivity.java:35)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.Activity.performCreate(Activity.java:5133)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-26 17:54:00.126: E/AndroidRuntime(12363):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-26 17:54:00.126: E/AndroidRuntime(12363):    ... 11 more

我正在按照这里的说明进行操作:https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en_US

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的日志告诉您在MainActivity的第36行生成NullPointerException。这就是为什么你的活动不会开始。

com.doritofacestudios.doritofacemath.MainActivity.onCreate(MainActivity.java:36)