I\'m creating a custom dialog containing an EditText so that I can get text data from the user:
final EditText newKey = (EditText) findViewById(R.id.dialog_r
This also happens if you try to access any view item with findViewById() before the onCreate() That is in my case i did:
private class ShareViaDialog extends Dialog {
private ImageView mainSmallIcon = findViewById(R.id.mainSmallIcon); //this is wrong
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
}}
so the correct way to avoid this error is:
private class ShareViaDialog extends Dialog {
private ImageView mainSmallIcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
mainSmallIcon = findViewById(R.id.mainSmallIcon); //should be here
}}