gpt4 book ai didi

java - 元素 未知

转载 作者:行者123 更新时间:2023-12-02 05:44:32 25 4
gpt4 key购买 nike

我正在尝试将 ad-mobs 广告添加到我的 Android 应用程序中,我已经安装了 Google play services 17 软件包,并将该软件包从 sdk>extras>google>google play service 复制到我的工作空间>myproject>lib> __ 并将 google-play-service_lib 文件导入到我的工作区。之后,我将 google-play-service.jar 添加到我的项目>java构建路径>库中,并且我还检查了顺序和导出。

但我徒劳地在 main.xml 中收到一个错误,因为 Element com.google.andriod.gsm.ads.AdView 未知,但它在 emluator 中编译并启动 Activity ,但出现运行时错误。

我浏览了很多帖子,但没有一个让我足够清楚。

以下是我的项目的主要内容:

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

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />

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


<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="com.SAI.banner.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"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

</application>

</manifest>

Main.xml:

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/bg"
tools:context="com.SAI.banner.MainActivity$PlaceholderFragment" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="@string/hello_world" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3131326757457805/934xxxxxxx" >
</com.google.android.gms.ads.AdView>

</RelativeLayout>

MainActivity.java

package com.SAI.banner;

import android.support.v7.app.ActionBarActivity;
import com.google.android.gms.ads.*;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {

@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);
}
}

提前感谢 Saikiran。请帮我解决这个问题。

最佳答案

我遇到了这个问题。当我通过以下步骤添加 Google Play 服务时,我的问题得到了解决:

  1. 将 Google Play 服务导入为项目。不要忘记选中“将项目复制到工作区”选项
  2. 右键单击您的应用项目,然后单击“属性”。选择安卓。单击“添加库”。从列表中选择 Google Play 服务。
  3. 如果您之前包含过 Jar,则应确保将其删除。
  4. 清理您的项目并重新构建。

关于java - 元素 <com.google.android.gms.ads.AdView> 未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24220200/

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