以下类不能被实例化: - com.google.ads.AdView Admob的 [英] The following classes could not be instantiated: - com.google.ads.AdView Admob

查看:129
本文介绍了以下类不能被实例化: - com.google.ads.AdView Admob的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Admob的SDK和我加入Admob的一个应用程序我正在开发,但我对XML收到错误。

I'm new to Admob sdk and I'm adding Admob on an app I'm developing but I'm getting error on the 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>

我添加了AD浏览报上的顶部,但我得到的错误。

I add the adView on the top but I'm getting error.

下面是错误:

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)

有人可以帮助我解决这个问题。谢谢你。

Can someone help me to fix this. Thank you.

推荐答案

你有没有添加AdActivity你的表现?

Have you added the AdActivity to your manifest?

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

请参阅:

<一个href="http://stackoverflow.com/questions/10447822/com-google-ads-adview-failed-to-instantiate">com.google.ads.AdView未能实例

<一个href="http://stackoverflow.com/questions/20035320/com-google-ads-adview-failed-to-instantiate-layout-issue">com.google.ads.AdView未能实例化布局问题

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

Also try changing the ads namespace from:

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

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

如果您使用的是谷歌AdMobSKD的最新版本,然后确保你更新的命名空间:

If you are using the latest version of Google AdMobSKD, then make sure you update the namespaces to:

com.google.android.gms.ads.AdView

这篇关于以下类不能被实例化: - com.google.ads.AdView Admob的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆