'How to find Edittext by id in a dialog?
I have a Dialog with an EditText, there, it asks for a wallet, and users write it.
After that, this wallet should be stored in a String, but it says that it's null.
Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
If I use an EditText from the Activity, it works fine. But it fails when I do it from the Dialog EditText (eTW).
There is my code.
private void showDialog(){
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.layout_walletdialog);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.bg_window);
ImageView btnClose = dialog.findViewById(R.id.btn_close);
Button btnSend = dialog.findViewById(R.id.btn_yes);
EditText wallet = (EditText) findViewById(R.id.eTW);
String value;
Solution 1:[1]
If eTW is defined in your walletdialog xml layout file, replace
EditText wallet = findViewById(R.id.eTW);
with
EditText wallet = dialog.findViewById(R.id.eTW);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sambhav. K |
