引起:java.lang.ClassCastException:com.google.android.material.textfield.TextInputLayout 無法在 com.example.cpp_project.Dashboard.onCreate(Dashboard.java: 29)
(Dashboard.java:29) = 用戶名=findViewById(R.id.username);
uj5u.com熱心網友回復:
TextInputLayout username = findViewById(R.id.username);
uj5u.com熱心網友回復:
ClassCastException是當我們試圖將一個類從一種型別不正確地轉換為另一種型別時在 Java 中引發的運行時例外。
在大多數情況下——取決于編譯器的支持——結果視圖會自動轉換為目標型別別。如果目標型別別不受約束,則可能需要顯式強制轉換。
例如:
EditText editText = (EditText)findViewById(R.id.username);
有關更多資訊,您可以在檔案findViewById和TextInputLayout中查看
uj5u.com熱心網友回復:
嘗試從 TextInputLayout 轉換為 TextInputEditText
username = (TextInputEditText)findViewById(R.id.username);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/444716.html
