亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

意外的隱式轉換為字符串:布局標記是 EditText 錯誤

意外的隱式轉換為字符串:布局標記是 EditText 錯誤

GCT1015 2023-03-23 15:35:33
我收到此錯誤。無法解決此錯誤,請幫助。項目中沒有其他錯誤。堅持這一點。主要活動 public class MainActivity extends AppCompatActivity {    String name, email;    FirebaseAuth mAuth;    Button submit;    DatabaseReference rootRef,demoRef;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title        getSupportActionBar().hide(); // hide the title bar        setContentView(R.layout.activity_main);        name =  findViewById(R.id.uName);        email = findViewById(R.id.uEmail);我正在使用約束布局。我已經把一切都設置正確了。<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@drawable/background"    android:gravity="center">    <EditText        android:id="@+id/uName"        android:layout_width="0dp"        android:layout_height="58dp"        android:layout_marginStart="48dp"        android:layout_marginLeft="48dp"        android:layout_marginTop="24dp"        android:layout_marginEnd="48dp"        android:layout_marginRight="48dp"        android:background="@drawable/border"        android:hint="@string/name"        android:paddingLeft="5dp"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="0.0"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/textView" />錯誤Unexpected implicit cast to String: layout tag was EditText less... (Ctrl+F1) Inspection info:Keeps track of the view types associated with ids and if it finds a usage of the id in the Java code it ensures that it is treated as the same type.  Issue id: WrongViewCast Type parameter T has incompatible upper bounds: View and String
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

您好,歡迎來到 Stack Overflow

實際上,您正試圖從您的布局中獲取對 editText 的引用。

name =  findViewById(R.id.uName);

該變量name不是EditText類型變量。它是String類型變量。這就是為什么您的應用程序顯示強制轉換異常。使用EditText代替String和替換

String name, email;

EditText name, email;


查看完整回答
反對 回復 2023-03-23
  • 1 回答
  • 0 關注
  • 206 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號