java - 无法实例化以下类 :com. google.android.gms.ads.AdView(打开类,显示错误日志)

标签 java android xml eclipse android-layout

我也已尽力(也将 Google 服务添加到我的应用中)。我关注 google admob 网站 1000 次,我受够了,请有人帮助我完成我的项目。 我希望在这里我能得到好的建议 谢谢

@Override
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     // Look up the AdView as a resource and load a request. 
    AdView adView = (AdView)this.findViewById(R.id.adView);
     AdRequest adRequest = new AdRequest.Builder().build();
     adView.loadAd(adRequest);
}

@Override
 public boolean onCreateOptionsMenu(Menu menu) { 
    //Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true; 
    }

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    //Handle action bar item clicks here. The action bar will 
    //automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) {
        return true;
    } 
    return super.onOptionsItemSelected(item); 
    }
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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="com.example.interadd.MainActivity" >


    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         ads:adSize="BANNER"
                         ads:adUnitId="ca-app-pub-2961758853938686/9050318854"/>

</LinearLayout>






<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE xml> <manifest
xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.interadd"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET"/> <uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"`enter code here`
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>

</manifest>

最佳答案

有时问题可能出现在 Graphical Layout

尝试这样..

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent" android:id="@+id/rltvLayout1"
android:layout_height="fill_parent">

    <com.google.android.gms.ads.AdView
     android:id="@+id/adViews" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        ads:adUnitId="aasss"
        ads:adSize="BANNER" />
    </RelativeLayout>

希望它能成功:)

关于java - 无法实例化以下类 :com. google.android.gms.ads.AdView(打开类,显示错误日志),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25751701/

相关文章:

Android Studio 引发此错误 : 'The emulator process for AVD was killed.'

android - 为什么AlertDialog.Builder 为自定义布局(Tablelayout)显示半空对话框

xml - '仅限字符'检查xsl字符串?

java - 使用java将XML文件中的数据加载到表中

java - 2d 游戏相机

java - 删除 LibGdx 缓冲区

php - 解析 XML 并回显结果

android - 如何在 Android style.xml 文件中使用自定义父级?

java - 无法使用java将文件从一个xml写入另一个xml

java - session 未创建异常 : Chrome version must be >= 65. 0.3325.0