我想將廣告添加到我的應用程序中,並且出現這個奇怪的錯誤,我無法看到我可能會得到它。以下是錯誤RelativeLayout和EditText錯誤
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): FATAL EXCEPTION: main
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): java.lang.RuntimeException: Unable to start activity ComponentInfo{coderaustin.com/coderaustin.com.Main}: java.lang.ClassCastException: android.widget.EditText
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.os.Looper.loop(Looper.java:123)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at java.lang.reflect.Method.invoke(Method.java:521)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at dalvik.system.NativeStart.main(Native Method)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): Caused by: java.lang.ClassCastException: android.widget.EditText
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at coderaustin.com.Main.onCreate(Main.java:79)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-30 20:02:48.889: ERROR/AndroidRuntime(3420): ... 11 more
正如你所看到的,它以某種方式獲得的EditText的一個實例出於此代碼
AdView adView = new AdView(this, AdSize.BANNER, "my pub code");
View view = findViewById(R.id.RelLayout);
if(view instanceof RelativeLayout) {
Log.e("It's layout", "fixed");
} else {
Log.e("NOOOO", "Instance of: " + view.getClass().getName());
}
**RelativeLayout layout = (RelativeLayout) findViewById(R.id.RelLayout);**
layout.addView(adView);
adView.setGravity(Gravity.BOTTOM);
// Add the adView to it
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
也許這件事情很明顯,我只是忘記它,我只是不」看看我要去哪裏錯了。感謝所有幫助。
編輯:只是櫃面你想看到我的佈局,這裏是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/RelLayout"
>
你可以發佈你的佈局? 79線是哪個? – user775598 2011-05-31 01:09:21
@ user775598我添加了帶有relativelayout的部件,並且其周圍的**行是第79行。 – Austin 2011-05-31 01:10:30
您是否有任何可以使用相同ID的EditText?除此之外,我不知道。 – user775598 2011-05-31 01:12:03