簡體   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