gpt4 book ai didi

java - Admob 立即崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 15:10:39 25 4
gpt4 key购买 nike

我正在尝试将 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

感谢您的帮助。

最佳答案

您的日志告诉您,您正在 MainActivity 的第 36 行生成 NullPointerException。这就是您的 Activity 无法启动的原因。

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

关于java - Admob 立即崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21370576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com