繁体   English   中英

在运行应用程序时显示错误

[英]showing error while running the app

错误如下:

02-11 13:24:31.561 5262-5262 /? E / AndroidRuntime:致命例外:主进程:com.example.vicky.project,PID:5262 java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.vicky.project / com.example.vicky.project.MainActivity }:java.lang.ClassCastException:无法将android.support.v7.widget.AppCompatTextView强制转换为android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)上的android.widget.EditText,位于android.app.ActivityThread.handleLaunchActivity( android.app.ActivityThread.-wrap12(ActivityThread.java)位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)位于android.os.Handler.dispatchMessage(Handler.java: 102)在android.os.Looper.loop(Looper.java:154)在android.app.ActivityThread.main(ActivityThread.java:6077)在com.android的java.lang.reflect.Method.invoke(本机方法) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)处的.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)原因:java.lang。 ClassCastException:android.support.v7.widget.AppCompatTextView无法转换为com.example.vicky.project.MainActivity.onCreate(MainActivity.java:30)上的android.widget.EditText,位于android.app.Activity.performCreate(Activity。于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)处的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)处的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)处的java:6662) android.os.Handler.dispatchMessage(Handler.java:102)上的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)上的android.app.ActivityThread.-wrap12(ActivityThread.java)。 android.app.ActivityThread.main(ActivityThread.java:6077)的Looper.loop(Looper.java:154)com.android.internal.os.ZygoteInit $的java.lang.reflect.Method.invoke(Native Method)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)上的MethodAndArgsCaller.run(ZygoteInit.java:865)

类强制转换类异常,因为您正尝试将TextView强制转换为EditText。

请仔细查看此内容{ android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText at com.example.vicky.project.MainActivity.onCreate(MainActivity.java:30)

您可以执行此操作{ TextView tv = (EditText/*change this to TextView*/) findViewById (R.id.textView) }如果您确定代码正确,则请在layout.xml中更改视图ID,然后从下面清理项目构建选项并重新构建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM