我在這個論壇上看到過許多類似的主題,但他們都沒有解決我的問題。 在我的代碼,我有這樣的事情:AdView Admob錯誤
import com.google.android.gms.R;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
...
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
而且它讓我看到2個錯誤(我打上紅色標記爲粗體文本):
-In第一行:「AdView adView =(AdView)this.findViewById(R.id。adView);」 - adView無法解析或不是字段
- 在最後一行中:「adView.loadAd(adRequest);」 - 類型android.view.ViewGroup無法解析。它是從所需的.class文件間接引用的
我不知道是什麼導致它。我之前也有一個缺乏「佈局」文件夾的問題,但是我使用eclipse new> other> android XML佈局文件生成了它。我還應該以某種方式使用清單鏈接它?
P.S.這是libGDX項目
編輯: 這裏是我的佈局/ activity_main.xml中的文件:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
安置自己的佈局文件你在哪裏放置adview – Psypher
你有沒有導入google play服務庫? –
@Ravi是的,Google play服務被導入到我的項目中。 Ranjith,我會把它張貼在那裏^ – urban07