ADmob - Problems with APP Ads

0

I did everything as the tutorial of the ADMOB website, I placed the layout in the XML, imported the path of Google Play Sevices and added the lines of code of the tutorial, my application compiles but does not open on the smartphone, a message appears of alerat saying that the app stopped and in the Eclipse log the following message appears (below), I need a help.

MessageinEclipse:

05-2610:47:02.007:E/AndroidRuntime(9092):java.lang.RuntimeException:UnabletostartactivityComponentInfo{your.CalculoHE.namespace/your.CalculoHE.namespace.CalculoHoraExtraActivity}:java.lang.NullPointerException

Class:

packageyour.CalculoHE.namespace;importorg.apache.cordova.DroidGap;importcom.google.android.gms.ads.*;importandroid.os.Bundle;publicclassCalculoHoraExtraActivityextendsDroidGap{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);super.setContentView(R.layout.main);super.setIntegerProperty("splashscreen", R.drawable.sobreaviso);
        super.loadUrl("file:///android_asset/www/index.html", 3000);

        // Consultar o AdView como um recurso e carregar uma solicitação.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());

    }    
   }     

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              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"
                         ads:adUnitId="ca-app-pub-6560993155721972/3382486845"
                         ads:adSize="BANNER"/>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hora extras"
    />
</LinearLayout>

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.CalculoHE.namespace"
    android:versionCode="4"
    android:versionName="1.2" >

    <uses-sdk android:minSdkVersion="9" />

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <application android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

       <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>


        <activity android:configChanges="orientation|keyboardHidden" android:name=".CalculoHoraExtraActivity"
            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.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>


    </application>
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

</manifest>
    
asked by anonymous 26.05.2014 / 15:50

1 answer

1

I looked at the DroidGap code in the Cordova repository. And from what I understand, it is not possible to do the way you did, including an android layout of yours with the AdsView, because it always overwrites the layout.

You will have to go this route:

import android.os.Bundle; 
import org.apache.cordova.*;
import com.google.ads.*;
import android.widget.LinearLayout;

public class MainActivity extends DroidGap {
    private static final String AdMob_Ad_Unit = "xxxxxxxxxxxxxxx";
    private AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")

        adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit); 
        LinearLayout layout = super.root; 
        layout.addView(adView); 
        AdRequest request = new AdRequest();

        // Comment this out before publishing.
        // request.addTestDevice(AdRequest.TEST_EMULATOR);
        adView.loadAd(request); 
    }
}

Another suggestion is that although the tutorial uses DroidGap , use CordovaActivity because DroidGap is marked as @Deprecated .

There is a tutorial on codetheory , which will to help you include Ads in your app.

    
26.05.2014 / 22:18