0

我已经看到了很多关于该主题的问题和答案,但我无法解决我的问题。

我正在尝试将 AdView 添加到我的活动 xml 文件中。这是我的 listactivity.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/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:id="@+id/mainLayout">  


<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="my great unit ID"
    ads:loadAdOnCreate="true" />

<EditText
    android:id="@+id/etSearch"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hladanyRetazecHint"
    android:singleLine="true" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tlForItems"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*" >
    </TableLayout>
</ScrollView>

在活动课上我有这样的东西:

AdView adView = (AdView) findViewById(R.id.adView);
             AdRequest r=new AdRequest();
             r.addTestDevice(AdRequest.TEST_EMULATOR);
             adView.loadAd(r);

我总是遇到异常,我的应用程序停止工作。这是堆栈跟踪:

09-01 17:52:06.035: I/Ads(2319): To get test ads on this device, call 

adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
09-01 17:52:06.395: D/AndroidRuntime(2319): Shutting down VM
09-01 17:52:06.435: W/dalvikvm(2319): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
09-01 17:52:06.495: E/AndroidRuntime(2319): FATAL EXCEPTION: main
09-01 17:52:06.495: E/AndroidRuntime(2319): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pataky.emulgators/com.pataky.emulgators.ListViewActivity}: java.lang.ClassCastException: com.google.ads.AdView cannot be cast to android.widget.EditText
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.os.Looper.loop(Looper.java:137)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread.main(ActivityThread.java:5039)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at java.lang.reflect.Method.invoke(Method.java:511)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at dalvik.system.NativeStart.main(Native Method)
09-01 17:52:06.495: E/AndroidRuntime(2319): Caused by: java.lang.ClassCastException: com.google.ads.AdView cannot be cast to android.widget.EditText
09-01 17:52:06.495: E/AndroidRuntime(2319):     at com.pataky.emulgators.ListViewActivity.initializeVariables(ListViewActivity.java:341)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at com.pataky.emulgators.ListViewActivity.onCreate(ListViewActivity.java:67)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.Activity.performCreate(Activity.java:5104)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-01 17:52:06.495: E/AndroidRuntime(2319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-01 17:52:06.495: E/AndroidRuntime(2319):     ... 11 more
09-01 17:52:06.645: D/dalvikvm(2319): DexOpt: --- BEGIN 'ads1914223767.jar' (bootstrap=0) ---
09-01 17:52:09.205: D/dalvikvm(2319): DexOpt: --- END 'ads1914223767.jar' (success) ---
09-01 17:52:09.205: D/dalvikvm(2319): DEX prep '/data/data/com.pataky.emulgators/cache/ads1914223767.jar': unzip in 3ms, rewrite 2555ms
09-01 17:52:10.576: I/Ads(2319): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"17769443340312675610","seq_num":"1","slotname":"ca-app-pub-1542281168882934\/3620846601","u_w":320,"msid":"com.pataky.emulgators","cap":"m,a","js":"afma-sdk-a-v6.4.1","bas_off":0,"net":"ed","app_name":"1.android.com.pataky.emulgators","hl":"en","gnt":3,"carrier":"310260","u_audio":4,"kw":[],"u_sd":0.75,"simulator":1,"ms":"iGcAH0KWwGTRMRvRfqniDpZyfbG0s78Au1Yqrs1FDPxAR2f3JCq9mXombj0Ov_VqldmoWIexv4TZFYH20yzFOqrvzVd_lNQWIm6GeJvX9EBfmchF81-G4Y8lXG_Ov-vjBByxO63yB0-HxFrlONgjOd4hoImUKw1TXIbo5hb_aPQ-ovs7SIChNjhpRy9RzCox8m39wEXJisz-S9A27EjEKnuxg81ccY89h4-Ab-FWF-oz7W6kYtdBwqe6WuSwbeE9Jw67V4pd_XKPMfu7GLLFXQRiBR-kjuMvmTZblj-tZexeC5-QgQ-bqiHNqlU_sEFy7owfaWOJ526hsBuSj_7JGQ","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","oar":0,"ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"u_h":533,"pt":1,"bas_on":0,"ptime":0});</script></head><body></body></html>

感谢您的建议。

4

1 回答 1

0

我也尝试清理项目并再次构建它,但它没有帮助,但最后我自己解决了它。

对我有用的是:我只是删除所有外部库并再次加载它。然后我重新启动 Eclipse,然后它运行。=)

于 2013-09-23T18:45:32.290 回答