-2

FirstI'm trying to display the spinner into a dialog, I'm calling the data from database into ArrayList via getData object and everything is working fine but in the last step I got the above error when I tried to assign the adapter to the spinner and here is my code :

    public class ViewDialogCities {
    public void showDialog(int layoutID , Activity activity){

        final Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(layoutID);
        Button OkButton =  dialog.findViewById(R.id.btn_dialog_ddl_ok);
        Button CloseDialogButton =  dialog.findViewById(R.id.btn_dialog_ddl_cancel);
        Spinner spn_ddl_dialog_list = findViewById(R.id.spn_ddl_dialog_list);


        //Define data object
        final GetData getData = new GetData();
        ArrayList<String> getListOf;


        //Retrieve data from data object and store it an ArrayList
        getListOf = getData.getListOf("R");

        //ArrayList to ArrayAdapter
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter
                ( HomeActivity.this, android.R.layout.simple_spinner_dropdown_item, getListOf);

        arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        // Assign ArrayAdapter to spinner
        spn_ddl_dialog_list.setAdapter(arrayAdapter);

        CloseDialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        OkButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        dialog.show();
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

2

you are getting null in getListOf. Make sure that the list is not null. also use like this.

Spinner spn_ddl_dialog_list = dialog.findViewById(R.id.spn_ddl_dialog_list);
jake oliver
  • 118
  • 1
  • 6
1

Spinner that you created is the view of the dialog.

so try this ,

Spinner spn_ddl_dialog_list = dialog .findViewById(R.id.spn_ddl_dialog_list);

in this the spinner will be refrenced by spinner view .

ADM
  • 20,406
  • 11
  • 52
  • 83
hamza khan
  • 141
  • 1
  • 11