gpt4 book ai didi

java - 尽管在 list 中声明了 AdActivity 错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:06:08 25 4
gpt4 key购买 nike

我正在尝试通过 Google Play 服务在 Android 应用程序中实现 Admob。

我已经在 list 文件中声明了广告 Activity ,但仍然收到错误:AdActivity with ...未在 list 文件中声明。

这是我到目前为止所做的事情:

xml 文件是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context=".AddActivity"
android:id="@+id/adView">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

Java 文件是:

package com.example.adtesting;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

public class AddActivity extends Activity {
final String adUnitId ="pub-*******";

private AdView adView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
// create adView
adView = new AdView(this);
adView.setAdUnitId(adUnitId);
adView.setAdSize(AdSize.BANNER);

//Lookup Linear Layout
RelativeLayout layout = (RelativeLayout) findViewById(R.id.adView);

//add AdView to it
layout.addView(adView);
//initiate generic request
AdRequest adRequest = new AdRequest.Builder().build();

// Load the adView withe the add request
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.add, menu);
return true;
}

}

list 文件是:

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

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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.example.adtesting.AddActivity"
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.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|
screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>

</manifest>

请注意,我引用了 Google Play 服务 SDK。

感谢您的帮助!

最佳答案

您已经声明了该包:

package="com.example.adtesting"

所以你只需要: android:name=".AddActivity"

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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

关于java - 尽管在 list 中声明了 AdActivity 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21969347/

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