Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RelativeLayout和EditText出错_Java_Android_Android Edittext_Android Relativelayout - Fatal编程技术网

Java RelativeLayout和EditText出错

Java RelativeLayout和EditText出错,java,android,android-edittext,android-relativelayout,Java,Android,Android Edittext,Android Relativelayout,我试图在我的应用程序中添加广告,但我遇到了一个奇怪的错误,我就是看不出我是如何得到它的。这里是错误 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.c

我试图在我的应用程序中添加广告,但我遇到了一个奇怪的错误,我就是看不出我是如何得到它的。这里是错误

  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"
>

我唯一能想到的是您的项目属性(包括ID)需要修复。当您向项目添加新ID/其他属性时,它们有时会不同步。在eclipse中,您可以右键单击项目并选择Android>FixProject属性。如果这不起作用,我有时不得不删除所有的.class文件(包括R.class)并重新编译


希望有帮助。

你能发布你的布局吗?哪一行是第79行?@user775598我添加了带有relativelayout的部分,并且在其周围带有**的那一行是第79行。您是否有可能拥有具有相同ID的EditText?除此之外,我没有任何线索。@user775598我真的不知道怎么做,但这是我在版面中的两个EditText,
code
谢谢,我以前试过,但它不起作用,但这次似乎起作用了,怪怪的。再次感谢。是的,“修复项目属性”这件事对我来说并不可靠(因此有时会进行完全的重新构建)。我发现,当我最近修改任何xml文件时,我必须使用Eclipse“Clean Project”来正确更新apk中的资源。这相当于删除@Gary提到的类文件。