2010-12-11 77 views
1

我对Java和Android应用程序非常陌生,所以,虽然这可能是其他人的一个选择,但却让我感到头疼。

应用程序应该加载,播放声音文件并关闭。没有AdMob,它就可以正常工作。

随着AdMob的启动,振动一次(它没有正常版本),正常运行,然后卡住,震动3次,并关闭投掷“抱歉!应用程序名称(进程PROCESS.NAME)已停止意外,请再试一次“。将AdMob集成到Android应用程序中的问题

我在我的第二个应用程序,我的第一个AdMob集成。

的SDK说明我跟着:http://www.admob.com/docs/AdMob_Android_SDK_Instructions.pdf

我所做的:
- 注册
- 拿到SDK
- 新增的.jar
- 增加了酒馆IDAdMobActivity定义跟踪市场安装来自SDK的代码说明在AndroidManifest.xml结尾并编辑了酒吧ID
- 增加了互联网权限
- 也增加了“ADMOB_ALLOW_LOCATION_FOR_ADS”
- 为attrs.xml添加了“AdMob AdView属性”(我使用Eclipse,因此我首先尝试将此添加到res/values/strings.xml,然后创建一个新的XML和添加的代码的话)



如果需要完整的代码,我会编辑这个职位。任何帮助表示赞赏。
预先感谢您
克里斯


(logcat的抛出两个小错误,而AdMob广告文件(我// - ed分进口和的AdView))
(通过AdMob logcat中抛出这个)

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 



使用完整的.java和XML代码进行编辑。我吸在Java中,它比AS,PHP,JavaScript和其他Web语言,以便diferent我通常使用

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发布的logcat的输出。 – Macarse 2010-12-11 04:13:17

回答

0

新增罐子

意味着你添加文件/库?如果没有,那就这样做。

编辑:

您正在使用错误onCreate。它应该是:

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

是的,我已经添加到/ libs,并将.jar添加到项目中。就像它在pdf中的sais – chris 2010-12-11 13:22:18

+0

我刚刚编辑我的答案。你的创建者看起来不对。 – Macarse 2010-12-11 17:00:11

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 
相关问题