gpt4 book ai didi

android - 以下类无法实例化 : - com. google.ads.AdView Admob

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:01:40 25 4
gpt4 key购买 nike

我是 Admob sdk 的新手,我正在将 Admob 添加到我正在开发的应用程序中,但我在 xml 上遇到错误。

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="fill_parent"
android:layout_height="fill_parent"
android:background="#0b2f50"
android:orientation="vertical" >

<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="SAMPLE"
ads:loadAdOnCreate="true" />

<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
</LinearLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="#081f34" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="45dp"
android:gravity="center"
android:orientation="horizontal" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:inputType="textNoSuggestions"
android:src="@drawable/logo2" />
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >

<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#8998a5" />

<ImageView
android:id="@+id/ImgVdetails"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="@layout/btn_save"
android:padding="10dp"
android:src="@drawable/info" />

<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#8998a5" />

<ImageView
android:id="@+id/refresh"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="@layout/btn_save"
android:padding="10dp"
android:src="@drawable/refresh" />

<ProgressBar
android:id="@+id/refreshBar"
android:layout_width="45dp"
android:layout_height="45dp"
android:padding="10dp"
android:visibility="gone" />

<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#8998a5" />

<ImageView
android:id="@+id/imageButton1"
android:layout_width="55dp"
android:layout_height="45dp"
android:background="@layout/btn_save"
android:contentDescription="@string/btnSettings"
android:padding="10dp"
android:src="@drawable/settings" />
</LinearLayout>
</RelativeLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8998a5" >
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c9d2da" >

<LinearLayout
android:id="@+id/wrap1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Today is "
android:textSize="14dp" />

<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14dp" />
</LinearLayout>

<View
android:id="@+id/v1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/wrap1"
android:background="#0b2f50" />

<LinearLayout
android:id="@+id/wrap2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v1"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Destination: "
android:textSize="20dp" />

<TextView
android:id="@+id/t2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text=""
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp" >

<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Distance: "
android:textSize="20dp" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="vertical" >

<TextView
android:id="@+id/t3a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
android:textStyle="bold" />

<TextView
android:id="@+id/t3b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<View
android:id="@+id/v2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/wrap2"
android:background="#0b2f50" />

<TextView
android:id="@+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/v2"
android:padding="5dp"
android:text="ALARM SETTINGS"
android:textSize="14dp" />

<LinearLayout
android:id="@+id/wrap3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title1"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >

<LinearLayout
android:layout_width="140dp"
android:layout_height="wrap_content" >

<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Mode: "
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In-Range"
android:textSize="15dp" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >

<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Sound: "
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/t5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text=""
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >

<LinearLayout
android:layout_width="140dp"
android:layout_height="wrap_content" >

<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Range: "
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/t6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="15dp" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >

<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Vibrate: "
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/t7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<View
android:id="@+id/v3"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/wrap3"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#0b2f50" />

<TextView
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/v3"
android:paddingLeft="5dp"
android:text="STATUS"
android:textSize="14dp" />

<TextView
android:id="@+id/t8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title2"
android:paddingLeft="15dp"
android:text=""
android:textSize="15dp" />
</RelativeLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#0a1d2e" />

<ToggleButton
android:id="@+id/TglBtn_setAlarm"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_weight="1.0"
android:background="@layout/btn_style"
android:textColor="#fff"
android:textOff="@string/TglBtn_setAlarmOn"
android:textOn="@string/TglBtn_setAlarmOff"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>

</LinearLayout>

我在顶部添加了 adView,但出现错误。

这里是错误:

The following classes could not be instantiated:
- com.google.ads.AdView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.


java.lang.NoSuchMethodError: com.google.ads.AdSize.createAdSize(Lcom/google/ads/AdSize;Landroid/content/Context;)Lcom/google/ads/AdSize;
at com.google.ads.AdView.a(SourceFile:161)
at com.google.ads.AdView.a(SourceFile:273)
at com.google.ads.AdView.a(SourceFile:394)
at com.google.ads.AdView.<init>(SourceFile:125)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)

谁能帮我解决这个问题。谢谢。

最佳答案

您是否已将 AdActivity 添加到您的 list 中?

    <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

参见:

com.google.ads.AdView failed to instantiate

com.google.ads.AdView failed to instantiate layout issue

还可以尝试更改广告命名空间:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

到:

xmlns:ads="http://schemas.android.com/apk/res-auto"

如果您使用的是最新版本的 Google AdMobSKD,请确保将命名空间更新为:

com.google.android.gms.ads.AdView

关于android - 以下类无法实例化 : - com. google.ads.AdView Admob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21692097/

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