0

在下面的错误报告中,它说它找不到片段“com.android.myproject.ad”——这让我很困惑,因为项目中没有“广告”类或对象。造成这种情况的唯一原因可能是 AdMob 库/SDK。

有其他人在 AdMob 中看到过这种情况吗?我检查了我正在使用的 AdMob SDK 的版本,它是最新的 (rev. 8)

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.myproject/com.android.myproject.ActivityMain}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.myproject.ad: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.myproject.ad: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Unknown Source)
at android.support.v4.app.FragmentState.instantiate(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreate(Unknown Source)
at com.android.myproject.ActivityMain.onCreate(Unknown Source)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
... 11 more
Caused by: java.lang.InstantiationException: com.android.myproject.ad
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)

AdMob 横幅通过 XML 布局可见:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

    <LinearLayout
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

        <!-- widgets like buttons and stuff -->

    </LinearLayout>

    <RelativeLayout
    android:id="@+id/bannersLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">

        <com.google.ads.AdView
        android:id="@+id/adViewBanner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adUnitId="@string/admob_id"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"
        android:layout_alignParentBottom="true"/>

    </RelativeLayout>

</LinearLayout>

为了保护我的应用免受这个讨厌的问题的影响,有没有更好的方法来展示 AdMob 广告(如果 AdMob 甚至是问题)。

4

0 回答 0