Question

The app i'm making displays user input before saving it. One of the spinners gets data from a database. When i press the "review" button my app crashes (something about a NullPointException) on this line final String estStatus = estType[row];

Here is the code.

    private void displayReviewDetails() {

      // Get what the user entered

       Spinner estSpinner    = (Spinner) findViewById (R.id.est_spinner);
       Spinner spinner = (Spinner) findViewById (R.id.ratingSpinner);



       EditText mealCost  = (EditText) findViewById (R.id.editTextMealCost);
       EditText mealType  = (EditText) findViewById (R.id.editTextMealType);
       EditText comments = (EditText) findViewById (R.id.editTextComments);

       DatePicker rDate = (DatePicker) findViewById (R.id.datePicker1);

        // final so we can reference them in the anonymous inner class below

        int row = estSpinner.getSelectedItemPosition();
        final String estStatus = estType[row];

        int row1 = spinner.getSelectedItemPosition();
        final String ratingStatus = estRating[row1];

        final String strMealCost = mealCost.getText().toString();
        final String strMealType = mealType.getText().toString();
        final String strComments = comments.getText().toString();

        final String rateDate = rDate.getDayOfMonth() + "/"
        + (rDate.getMonth() + 1) + "/" + rDate.getYear();

        // Create and display the Alert dialog
        new AlertDialog.Builder(this)
        .setTitle("Details entered")
        .setMessage(
        "\n " + estStatus      + 
        "\n " + ratingStatus   + 
        "\n " + strMealCost    +
        "\n " + strMealType    + 
        "\n " + strComments    +
        "\n " + rateDate   )
        .setNeutralButton("Back",
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        // do nothing - it               will just close when clicked
        }
        })

        .setPositiveButton("Save",
           new DialogInterface.OnClickListener() {

           @Override
           public void onClick(DialogInterface dialog,  int which) {
                // save the details entered if "Save" button clicked
                saveReviews(estStatus, ratingStatus, strMealCost, strMealType,
                strComments, rateDate);
            }
        }).show();
Was it helpful?

Solution

You can also use getSelectedItem().toString();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top