06
Май
2017

NullPointerException при вызове EditText.getText()

public void foodbuttonclick(View view) {
    final EditText foodtext;
    final TextView textView2;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    textView2 = (TextView) view.findViewById(R.id.textView2);
    foodtext = (EditText) view.findViewById(R.id.input_text);
    builder.setTitle("Еда")
        .setMessage("Введите сумму:")
        .setCancelable(true)
        .setView(dialog_view)
        .setNegativeButton("Подтведрить",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    String foodstr = foodtext.getText().toString();
                    //String foodstr = (String.valueOf(foodint));
                    dialog.dismiss();
                    textView2.setText(foodstr);
                }
        });
        builder.show();
    }

NullPointerException Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference AndroidStudio пишет, что проблема com.example.andrew.moneysaver.MainActivity$2.onClick(MainActivity.java:94) в строке String foodstr = foodtext.getText().toString();

Источник: https://ru.stackoverflow.com/questions/662598/nullpointerexception-%D0%BF%D1%80%D0%B8-%D0%B2%D1%8B%D0%B7%D0%BE%D0%B2%D0%B5-edittext-gettext

Share

Тебе может это понравится...