1

Hi i tried to include ads in my app !!!

I added external jars added permissions , activity as from the tutorials but there is a problem when i added the ad in the layout

it shows this error

"java.lang.NullPointerException"

I am using Min sdk version Android 2.3.3

Target 2.3.3

API level: 10

Project gets build but does not open !!!!

Below is my code:

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>

Please help me to solve the problem thankssss :-)

aiohanar
  • 11
  • 4

2 Answers2

0

Couple of things I have noticed in your code:

First, the target SDK should be at least API 13 (Ref. Link: Admob Error in Eclipse for android:configChanges)

Change it look like this:

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="13"/>

Second, this part in your code posted in the OP:

<activity android:name="com.google.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"></activity>

should be:

<activity
    android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>

UPDATE

For more reference, read up on this link. Once you have the site open, change to the Android tab (you will on iOS by default)

Community
  • 1
  • 1
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
0

After you've properly positioned your adView, try this out.

Step 1:
- Right click on your project.
- Locate the new Google_Admob_Jar file at C:\Users\YOURNAME\android-sdks\extras\google\admob_ads_sdk, if you have the latest version.
- Click OK

Step 2:
- Right click on your project.
- Properties-> Java_Build_Path-> Order_and_Export.
- Select the Google_Admob_Jar.
- Click ok

Hope it helps :)

smoothBlue
  • 203
  • 4
  • 12
  • the problem is not the ad is getting loaded the problem is that whenever i included the ad the application stops working and the reason is "java.lang.NullPointerException" – aiohanar Jan 15 '13 at 11:18
  • the problem comes only after i add ad in xml layout. the application starts without the ad. But when i include the ad in xml the problem arises – aiohanar Jan 15 '13 at 11:22