Android ClassCastException:请帮我找出哪里出了问题

Android ClassCastException:请帮我找出哪里出了问题,android,java.lang.class,Android,Java.lang.class,好这里是XML代码 唉,我已经试着解决这个问题一个多小时了,我不知道发生了什么。。我在最后一行代码中得到错误:ph0ne=(EditText)findviewbyd(R.id.testphone) 编辑:由于某些原因,我无法添加XML代码。。这里是stackTrace: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spiratessgmail.myapplication/com.spiratess

好这里是XML代码

唉,我已经试着解决这个问题一个多小时了,我不知道发生了什么。。我在最后一行代码中得到错误:
ph0ne=(EditText)findviewbyd(R.id.testphone)

编辑:由于某些原因,我无法添加XML代码。。这里是stackTrace:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spiratessgmail.myapplication/com.spiratessgmail.myapplication.MyActivity}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.EditText
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.EditText
            at com.spiratessgmail.myapplication.MyActivity.onCreate(MyActivity.java:33)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
意味着你应该改变

 ph0ne= (EditText) findViewById(R.id.testphone);

ph0ne=(LinearLayout)findviewbyd(R.id.testphone)


或者,如果您的视图应该是
EditText
,则必须在
EditText

中更改id为testphone(即
LinearLayout
)的视图,因为正如您在错误日志中看到的,我想您只是在引用设计id时犯了一个错误,请检查
EditText
的id,此id
R.id.testphone
指的是一个
线性布局
,只需检查XML中的
编辑文本
的id即可

并提供堆栈跟踪。很抱歉,我是新手,堆栈跟踪是什么?为什么我不能发送XML代码..我们需要堆栈跟踪(LogCat中显示的红色错误日志),但我猜R.id.testphone的类型不是“EditText”。该或“ph0ne”的类型错误。你能发布更多的代码吗?你能发布你的xml布局吗?那不行。如果我将其更改为红色下划线,它表示需要EditText,但找到了LinearLayout,那么问题是“ph0ne”有一种LinearLayout类型。请将其更改为“TextView ph0ne;”在初始化中。@jojo可能是,因为您的结束标记是。如果你放了一个标签,你的关闭标签必须是。或者,您可以删除结束标记,仅使用第一个标记在最终角度之前添加斜线bracket@Tyler不,这给了我和开始时一样的问题:android.widget.LinearLayout不能转换为android.widget。EditText@jojo是的,我们确实需要xml。我不确定“testphone”应该是LinearLayout还是EditText,但问题是“testphone”和“ph0ne”不是同一类型。因此,如果希望它是EditText,请将“ph0ne”定义为编辑文本,将其强制转换为(EditText),并在xml中确保id为“testphone”的元素是EditTextNope:(。
android.widget.LinearLayout cannot be cast to android.widget.EditText
 ph0ne= (EditText) findViewById(R.id.testphone);