I dont understand, the dialog and everything works but as soon as I get the value from the EditText and assign it to val, run the app it crashes within the onClick on success.
I get an error: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
public void createDialogBox() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Get the layout inflater
LayoutInflater inflater = this.getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
//
builder.setView(R.layout.custom_dialog)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// On success
EditText text = (EditText) findViewById(R.id.shopping_list_recycler_view);
String val = text.getText().toString();
adapter = new ShoppingListViewAdapter(test, MainShoppingListViewActivity.this);
recyclerView.setAdapter(adapter);
adapter.addTest(new Data(val, "Created by: Me"));
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// On failure
Toast.makeText(MainShoppingListViewActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
})
// Desired icon for the dialog box
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
