[英]android admob not working
嗨,我試圖在我的應用程序中加入廣告!
我從教程中添加了外部jar,添加了權限,活動,但是在布局中添加廣告時出現了問題
它顯示此錯誤
“ java.lang.NullPointerException”
我正在使用Min SDK版本Android 2.3.3
目標2.3.3
API級別:10
項目獲得構建但無法打開!!!!
下面是我的代碼:
enter code here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rhstudioss.adaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>
<activity
android:name="com.rhstudioss.adaps.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>
</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/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<com.google.ads.AdView android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MyID"
ads:loadAdOnCreate="true"
ads:adSize="BANNER"
/>
</RelativeLayout>
請幫我解決問題謝謝:-)
我在您的代碼中注意到的幾件事:
首先 ,目標SDK至少應為API 13(參考鏈接: Eclipse中針對android:configChanges的Admob錯誤 )
更改如下所示:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="13"/>
其次 ,這部分代碼在OP中發布:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>
應該:
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
更新
有關更多參考,請閱讀此鏈接。 打開網站后,轉到Android選項卡(默認情況下將在iOS上)
正確放置adView后,請嘗試一下。
第1步:
-右鍵點擊您的項目。
-如果您使用的是最新版本,請在C:\\ Users \\ YOURNAME \\ android-sdks \\ extras \\ google \\ admob_ads_sdk中找到新的Google_Admob_Jar文件。
-點擊確定
第2步:
-右鍵點擊您的項目。
-屬性-> Java_Build_Path-> Order_and_Export。
-選擇Google_Admob_Jar。
-點擊確定
希望能幫助到你 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.