I have action bar drop-down in my android application. When user click a item from the drop-down. I added a AlertDialogBuilder to get some user data from user, if user press ok it will save the data. When I run the code I got this exception.

this is the code I'm using
@Override
public boolean onNavigationItemSelected(final int i, long l) {
    final ArrayList<Host> hosts = HostFactory.getHosts(this.getApplicationContext());
    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(this);
    View promptsView = li.inflate(R.layout.auto_discovery_prompt, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            this);
    // set prompts.xml to alertdialog builder
    alertDialogBuilder.setView(promptsView);
    final EditText txtDeviceName = (EditText) promptsView.findViewById(R.id.txtdevicename_editTextDialogUserInput);
    final EditText txtUsername = (EditText) promptsView.findViewById(R.id.txtusername_editTextDialogUserInput);
    final EditText txtPassword = (EditText) promptsView.findViewById(R.id.txtpassword_editTextDialogUserInput);
    final EditText txtPort = (EditText) promptsView.findViewById(R.id.txtport_editTextDialogUserInput);
    String mac=navSpinner.get(i).getMacaddress();
    txtDeviceName.setText(navSpinner.get(i).getTitle());
    txtPort.setText(navSpinner.get(i).getPort());
    for(SpinnerNavItem items:navSpinner)
    {
        if(items.getTitle().toString()!="Select your Device" )
        {
            // set dialog message
            alertDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                @TargetApi(Build.VERSION_CODES.GINGERBREAD)
                                public void onClick(DialogInterface dialog,
                                                    int id) {
                                    // get user input and set it to result
                                    // edit text
                                    //result.setText(userInput.getText());
                                    String dd=txtPassword.getText().toString();
                                    Host savecurrent_selected_host =new Host();
                                    savecurrent_selected_host.name=txtDeviceName.getText().toString();
                                    savecurrent_selected_host.addr=navSpinner.get(i).getIPaddress().toString();
                                    try {
                                        savecurrent_selected_host.port = Integer.parseInt(txtPort.getText().toString());
                                    } catch (NumberFormatException e) {
                                        savecurrent_selected_host.port = Host.DEFAULT_HTTP_PORT;
                                    }
                                    savecurrent_selected_host.user=txtUsername.getText().toString();
                                    savecurrent_selected_host.pass=txtPassword.getText().toString();
                                    savecurrent_selected_host.esPort = Host.DEFAULT_EVENTSERVER_PORT;
                                    savecurrent_selected_host.timeout = Host.DEFAULT_TIMEOUT;
                                    savecurrent_selected_host.access_point="";
                                    if(!(navSpinner.isEmpty()&& navSpinner.get(i).getMacaddress().toString().isEmpty()))
                                        savecurrent_selected_host.mac_addr=navSpinner.get(i).getMacaddress().toString();
                                    else
                                        savecurrent_selected_host.mac_addr="";
                                    savecurrent_selected_host.wol_port = Host.DEFAULT_WOL_PORT;
                                    savecurrent_selected_host.wol_wait = Host.DEFAULT_WOL_WAIT;
                                    HostFactory.addHost(getApplicationContext(), savecurrent_selected_host);
                                    HostFactory.saveHost(getApplicationContext(),savecurrent_selected_host);
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                                    int id) {
                                    dialog.cancel();
                                }
                            });
            // create alert dialog
            alertDialog = alertDialogBuilder.create();
            // show it
            if(!alertDialog.isShowing())
                alertDialog.show();
    }
}
How can I fix this problem?( application is braking when come to  alertDialog.show() )