gpt4 book ai didi

android - Galaxy Nexus 上的 AdMob - Android 应用程序自行关闭

转载 作者:行者123 更新时间:2023-11-30 03:52:09 28 4
gpt4 key购买 nike

我编写了一个简单的应用程序来测试一些东西。一件事是 AdMob。

在大多数 Android 手机上它都可以使用,但在 Galaxy S3 或 Galaxy Nexus 或平板电脑上则不行。也许更高的分辨率有问题?问题是应用程序在启动时立即关闭。我尝试在 XML 上集成 AdMob,但这在新版本中确实不起作用。

这是我的 AdMob 代码。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
AdView adView = new AdView(this, AdSize.BANNER, "replaced id with this");
//adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
LinearLayout layout = (LinearLayout)findViewById(R.id.LayoutMain);
layout.addView(adView,0);
adView.loadAd(adRequest);

这是 LogCat

12-20 18:39:18.056: I/dalvikvm(541):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-20 18:39:18.066: I/dalvikvm(541): at dalvik.system.NativeStart.main(Native Method)
12-20 18:39:18.086: D/AndroidRuntime(541): Shutting down VM
12-20 18:39:18.096: W/dalvikvm(541): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-20 18:39:18.206: E/AndroidRuntime(541): FATAL EXCEPTION: main
12-20 18:39:18.206: E/AndroidRuntime(541): java.lang.RuntimeException: Unable to start activity ComponentInfo{at.android.dertestloerk/at.android.dertestloerk.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.os.Looper.loop(Looper.java:137)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-20 18:39:18.206: E/AndroidRuntime(541): at dalvik.system.NativeStart.main(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Activity.setContentView(Activity.java:1835)
12-20 18:39:18.206: E/AndroidRuntime(541): at at.android.dertestloerk.MainActivity.onCreate(MainActivity.java:27)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Activity.performCreate(Activity.java:4465)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 11 more
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: java.lang.reflect.InvocationTargetException
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Constructor.constructNative(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 23 more
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: java.lang.OutOfMemoryError
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.nativeCreate(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.content.res.Resources.loadDrawable(Resources.java:1937)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.View.<init>(View.java:2780)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.View.<init>(View.java:2717)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.ViewGroup.<init>(ViewGroup.java:379)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 26 more
12-20 18:39:23.096: I/Process(541): Sending signal. PID: 541 SIG: 9

这是我的 XML 布局

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hintergrund"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageViewLoerg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/animatedloerg"
tools:ignore="ContentDescription" /> </LinearLayout>

希望你能帮上忙.-)

最佳答案

这与 Admob 无关。错误在:

18:39:18.206: E/AndroidRuntime(541): Caused by: android.view.InflateException: Binary XML file line #1: 错误膨胀类 android.widget.RelativeLayout 12-20 18:39:18.206: E/AndroidRuntime(541): 在

也就是说,在您以编程方式在 Admob AdView 中转换广告之前很久,尝试加载 XML 布局时就会崩溃。

看看你的布局,那里有问题。

关于android - Galaxy Nexus 上的 AdMob - Android 应用程序自行关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13977452/

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