简体   繁体   中英

AdMob error at running app

This is a java code:

  package h.a.s.i;

  import com.google.ads.AdRequest;
  import com.google.ads.AdSize;
  import com.google.ads.AdView;
  //and next



  public class about extends Activity {
  private static final String MY_BANNER_UNIT_ID = "xxx";


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);


    LinearLayout layout = (LinearLayout)findViewById(R.id.admob);


    AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);


    layout.addView(adView);


    AdRequest request = new AdRequest();

    adView.loadAd(request);             




    final Button back = (Button) findViewById(R.id.back);
     back.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            finish();
        }

     }); }

 } 

and this XML:

   <LinearLayout
    android:layout_width="250dp"
    android:layout_height="70dp"
    android:name="@+id/admob"
    android:layout_alignParentTop="true" >
   </LinearLayout> 

and Manifest:

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="h.a.s.i"
      android:versionCode="1"
      android:versionName="1.0" >
      <application
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name" >
     <activity
        android:name=".main"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
     </activity>
     <activity android:name=".cpu" 
            android:label="CPU"
            android:screenOrientation="portrait"/>
     <activity android:name=".options" 
            android:label="Options"
            android:screenOrientation="portrait"/>
      <activity android:name=".battery" 
            android:label="Baterry"
            android:screenOrientation="portrait"/>
     <activity android:name=".about" 
            android:label="About"
            android:screenOrientation="portrait"/>
      <activity android:name=".system" 
                android:label="Systém"
            android:screenOrientation="portrait"/>
     <activity android:name="h.a.s.i.memory" 
            android:label="Task Killer"
            android:screenOrientation="portrait"/>
     <activity android:name="com.google.ads.AdActivity"
          android:configChanges="orientation|keyboard|keyboardHidden"/>

    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-sdk android:minSdkVersion="7" />
    </manifest>  

The AdMob lib I'm include for official guide.

And Eclipse LogCat:

    06-13 15:06:49.491: E/dalvikvm(457): Could not find class 'com.google.ads.AdView',                    referenced from method h.a.s.i.about.onCreate 

and then seeing a fall of OnCreate()

In Emulator when open a about page(class about) so application crashed. And in Eclipse not appear any Error in Error log or anywhere else. Thank you for each help. :)

To fix the bug do the following:

1- Remove the libraries from the standard Java build path : Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the “Android XX” (2.2 in my case) and the “Android Dependencies”

2- Rename the libraries folder (or create it if it does not exist) from “lib” to “ libs ” and locate the jar file inside it By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project

3- Clean the project

ALSO you may need to declare com.google.ads.AdActivity in AndroidManifest.xml.

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

ENJOY :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM