1

我已经浏览了所有我能找到的例子,但我不确定错误在哪里。我的代码与另一个应用程序相同,我只是尝试将 admob 添加到帐户中。这是我可以从我的 logcat 中获取的内容。

    09-29 13:19:28.026: D/ActivityThread(29906): setTargetHeapUtilization:0.25
09-29 13:19:28.026: D/ActivityThread(29906): setTargetHeapIdealFree:8388608
09-29 13:19:28.026: D/ActivityThread(29906): setTargetHeapConcurrentStart:2097152
09-29 13:19:28.256: D/dalvikvm(29906): GC_FOR_ALLOC freed 55K, 31% free 14739K/21059K, paused 16ms, total 16ms
09-29 13:19:28.346: D/dalvikvm(29906): GC_CONCURRENT freed <1K, 21% free 24914K/31239K, paused 12ms+22ms, total 45ms
09-29 13:19:28.586: I/webclipboard(29906): clipservice: android.sec.clipboard.ClipboardExManager@42d9ebf0
09-29 13:19:28.617: V/webkit(29906): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {42d994a8}
09-29 13:19:28.667: I/webclipboard(29906): clipservice: android.sec.clipboard.ClipboardExManager@42d9ebf0
09-29 13:19:28.667: V/webkit(29906): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {42dc21c8}
09-29 13:19:28.747: V/webkit(29906): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {42e2db50}
09-29 13:19:28.747: I/webclipboard(29906): clipservice: android.sec.clipboard.ClipboardExManager@42d9ebf0
09-29 13:19:28.767: I/Ads(29906): To get test ads on this device, call adRequest.addTestDevice("512CF178FE3E3613A01DC3FBA545BD86");
09-29 13:19:28.897: W/dalvikvm(29906): threadid=1: thread exiting with uncaught exception (group=0x41480438)
09-29 13:19:28.897: E/AndroidRuntime(29906): FATAL EXCEPTION: main
09-29 13:19:28.897: E/AndroidRuntime(29906): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mrj05hua.hanselgretelwhfree/com.mrj05hua.hanselgretelwhfree.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread.access$700(ActivityThread.java:143)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.os.Looper.loop(Looper.java:137)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread.main(ActivityThread.java:4950)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at java.lang.reflect.Method.invokeNative(Native Method)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at java.lang.reflect.Method.invoke(Method.java:511)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at dalvik.system.NativeStart.main(Native Method)
09-29 13:19:28.897: E/AndroidRuntime(29906): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.widget.ScrollView.addView(ScrollView.java:316)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:750)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.Activity.setContentView(Activity.java:1914)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at com.mrj05hua.hanselgretelwhfree.MainActivity.onCreate(MainActivity.java:73)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.Activity.performCreate(Activity.java:5179)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
09-29 13:19:28.897: E/AndroidRuntime(29906):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
09-29 13:19:28.897: E/AndroidRuntime(29906):    ... 11 more
09-29 13:19:28.957: I/Ads(29906): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"7723615705340179905","seq_num":"1","slotname":"pub-4235852256372242","u_w":640,"msid":"com.mrj05hua.hanselgretelwhfree","js":"afma-sdk-a-v6.4.1","bas_off":0,"net":"wi","app_name":"1.android.com.mrj05hua.hanselgretelwhfree","hl":"en","gnt":13,"carrier":"311480","u_audio":1,"kw":[],"u_sd":2,"ms":"IV6O237njvDEvF1ofv78lOtjwh57ebkvua5-rxjoFyAyMTipUBB2050GvmOPvdWNPsxLTPq4F1GRW1dJdqubdcv0uviIrWVHoPHn0rAGzh4DUHlSTfXHBcAiMsW5AXD6hn-AafG2QBHLoY5vkpaWhotmzeAq-VRV5udolUxpqQxMj7rfhI9wXn5T8o5ths5UUcLfHFTR4Hd7cKftCJQkbazmOsQrDCu4UGju2VDmS5pZ5ZNbvQePhv9OKQHcbNpRGbTtbU_DMKCU3xjqWiaON4LmdTWjwTii0ahlDwdIgSvJvOh9TUMUeDD_ac3jAhw64hZUFqNNkeuZk5UeJ2XuvQ","mv":"80230011.com.android.vending","isu":"512CF178FE3E3613A01DC3FBA545BD86","format":"320x50_mb","oar":0,"ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"u_h":360,"pt":2,"bas_on":0,"ptime":0});</script></head><body></body></html>
4

1 回答 1

1

问题是在您的布局中,您在滚动视图下而不是在父布局下有 admob。ScrollViews 只能承载一个视图,而您真正想要的是主要部分滚动,然后广告像页脚一样保持在底部不变。

根据日志可以看出这一点:

Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
于 2013-09-29T18:29:51.900 回答