I am trying to open a custom dialog box that cover the full interface of the device .But I don't know it is throwing exception Please check my code and help me to solve this issue.
On click of the listview item
data.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
passengerInformationPopup();
}
});
**The Function to open the Dialog**
public void passengerInformationPopup() {
final Dialog dialog= new Dialog(getBaseContext());
dialog.setContentView(R.layout.passenger_details_dialog);
String[] tittlearray ={"Mr.","Mrs.","Ms"};
Spinner tittleSpinner = (Spinner) dialog.findViewById(R.id.Tittle);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, tittlearray);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
tittleSpinner.setAdapter(dataAdapter);
dialog.show();
}
Exception
08-14 16:39:50.338: E/AndroidRuntime(30294): FATAL EXCEPTION: main
08-14 16:39:50.338: E/AndroidRuntime(30294): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.view.ViewRootImpl.setView(ViewRootImpl.java:656)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:328)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:226)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:151)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.app.Dialog.show(Dialog.java:277)
08-14 16:39:50.338: E/AndroidRuntime(30294): at com.example.userdetails.MainActivity.passengerInformationPopup(MainActivity.java:181)
08-14 16:39:50.338: E/AndroidRuntime(30294): at com.example.userdetails.MainActivity$5.onItemClick(MainActivity.java:149)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.widget.AbsListView.performItemClick(AbsListView.java:1114)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2937)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.widget.AbsListView$1.run(AbsListView.java:3695)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.os.Handler.handleCallback(Handler.java:615)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.os.Looper.loop(Looper.java:153)
08-14 16:39:50.338: E/AndroidRuntime(30294): at android.app.ActivityThread.main(ActivityThread.java:4987)
08-14 16:39:50.338: E/AndroidRuntime(30294): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 16:39:50.338: E/AndroidRuntime(30294): at java.lang.reflect.Method.invoke(Method.java:511)
08-14 16:39:50.338: E/AndroidRuntime(30294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-14 16:39:50.338: E/AndroidRuntime(30294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-14 16:39:50.338: E/AndroidRuntime(30294): at dalvik.system.NativeStart.main(Native Method)