2010-12-11 38 views
1

Je suis un nouveau venu dans les applications Java et Android, alors que cela peut être un gage pour d'autres, cela me donne mal à la tête.

L'application devrait charger, lire un fichier son et fermer. Et cela fonctionne très bien sans l'AdMob. Avec l'AdMob, il démarre, vibre une fois (il ne fonctionne pas dans la version normale), fonctionne normalement, puis reste bloqué, vibre 3 fois et ferme le lancement d'un "Désolé! L'application NAME (processus PROCESS.NAME) est arrêtée De manière inattendue, veuillez réessayer ".Problèmes liés à l'intégration d'AdMob dans l'application Android

Je suis sur ma deuxième application, et ma première intégration AdMob.

Les instructions du SDK j'ai suivi: http://www.admob.com/docs/AdMob_Android_SDK_Instructions.pdf

Ce que je l'ai fait:
- Enregistré
- Vous avez le SDK
- Ajout de la .jar
- Ajout de l'ID pub, AdMobActivity définition et Suivre le marché Installe le code à partir des instructions du SDK à la fin de AndroidManifest.xml et édite l'ID du pub
- Ajout de l'autorisation Internet
- Ajout « ADMOB_ALLOW_LOCATION_FOR_ADS » trop
- Ajout de « AdMob AdView attributs » à attrs.xml (j'utiliser Eclipse, donc j'ai essayé d'ajouter à res/valeurs/strings.xml, nous constituons un nouveau xml et a ajouté le code pour lui) Si le code complet



est nécessaire je vais modifier ce poste. Toute aide est appréciée.
Nous vous remercions à l'avance
Chris


(LogCat lance deux petites erreurs sans les fichiers AdMob (I // - ed l'importation et adview))
(LogCat AdMob lance cette)

12-11 14:50:00.266: ERROR/beep(284): started0 
12-11 14:50:00.346: ERROR/AndroidRuntime(284): Uncaught handler: thread main exiting due to uncaught exception 
12-11 14:50:00.368: ERROR/AndroidRuntime(284): java.lang.RuntimeException: Unable to start activity ComponentInfo{seven.kitty.purr/seven.kitty.purr.KittyPurr}: java.lang.NullPointerException 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.os.Looper.loop(Looper.java:123) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at java.lang.reflect.Method.invoke(Method.java:521) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at dalvik.system.NativeStart.main(Native Method) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284): Caused by: java.lang.NullPointerException 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at seven.kitty.purr.KittyPurr.onCreate(KittyPurr.java:20) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
12-11 14:50:00.368: ERROR/AndroidRuntime(284):  ... 11 more 
12-11 14:50:00.407: ERROR/dalvikvm(284): Unable to open stack trace file '/data/anr/traces.txt': Permission denied 



Modification avec des codes .java et XML complets. Je suce à Java, il est si diferent que AS, PHP, JavaScript et d'autres langages web j'utilise habituellement

KittyPurr.java

package seven.kitty.purr; 

import android.app.Activity; 
import android.media.MediaPlayer; 
import android.media.MediaPlayer.OnCompletionListener; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.TextView; 
import com.admob.android.ads.AdManager; 
import com.admob.android.ads.AdView; 

public class KittyPurr extends Activity 
{ 
    private MediaPlayer mMediaPlayer; 
    public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    playAudio(); 



    } 

    private void playAudio() { 
    try { 
    mMediaPlayer = MediaPlayer.create(this, R.raw.purrr); 
    mMediaPlayer.setLooping(false); 
    Log.e("beep","started0"); 
    mMediaPlayer.start(); 

    AdView adView = (AdView)findViewById(R.id.ad); 
    adView.requestFreshAd(); 

    mMediaPlayer.setOnCompletionListener(new OnCompletionListener() { 
      public void onCompletion(MediaPlayer arg0) { 
     finish(); 
     } 
    }); 
    } catch (Exception e) { 
    Log.e("beep", "error: " + e.getMessage(), e); 
    } 
    } 

    @Override 
    protected void onDestroy() { 
    super.onDestroy(); 
    if (mMediaPlayer != null) { 
    mMediaPlayer.release(); 
    mMediaPlayer = null; 
    } 
    } 
} 



main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:myapp="http://schemas.android.com/apk/res/seven.kitty.purr" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<com.admob.android.ads.AdView 
android:id="@+id/ad" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/> 
</LinearLayout> 



attrs.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<declare-styleable name="com.admob.android.ads.AdView"> 
<attr name="backgroundColor" format="color" /> 
<attr name="primaryTextColor" format="color" /> 
<attr name="secondaryTextColor" format="color" /> 
<attr name="keywords" format="string" /> 
<attr name="refreshInterval" format="integer" /> 
</declare-styleable> 
</resources> 
+0

Plz publier la sortie de logcat. – Macarse

Répondre

0

Ajouté le pot

signifie que vous ajoutez le fichier/libs? Si non, faites-le.

EDIT:

Vous utilisez le mauvais onCreate. Il devrait être:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
... 
} 
+0

ouais, j'ai ajouté cela à/libs, et ajouté le .jar au projet aussi. tout comme il sais dans le .pdf – chris

+0

Je viens d'éditer ma réponse. votre oncreate semble faux. – Macarse

0
you need to add the following this in xml and if you want to test it in emulator 
    then u need to set the **adrequest.setTestDevice(true)** 

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     **xmlns:myapp="http://schemas.android.com/apk/libs/com.google.ads"** 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
    <com.google.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    **myapp:adUnitId="Your Admob ID" 
    myapp:adSize="BANNER"** 
    /> 
    </LinearLayout> 


in the AndroidManifest.xml you need to add the following thing 

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

and one thing you need to consider that u need to compile project with android 3.2 or above