Hi
When I try to make PopupWindow at onCreate(), the BadTokenException is
thrown.
If there is some delays when make PopupWindow, the Exception does not
occur.
But It doesn't seem a good solution.
How can I make PopupWindow at onCreate() without Exception?
05-09 21:36:09.820: ERROR/AndroidRuntime(8803):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{exam.pop/exam.pop.popActivity}:
android.view.WindowManager$BadTokenException: Unable to add window --
token null is not valid; is your activity running?
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2663)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.os.Looper.loop(Looper.java:123)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
java.lang.reflect.Method.invokeNative(Native Method)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
java.lang.reflect.Method.invoke(Method.java:521)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
dalvik.system.NativeStart.main(Native Method)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): Caused by:
android.view.WindowManager$BadTokenException: Unable to add window --
token null is not valid; is your activity running?
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.view.ViewRoot.setView(ViewRoot.java:505)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.view.Window$LocalWindowManager.addView(Window.java:424)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
exam.pop.popActivity.makepopup(popActivity.java:41)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
exam.pop.popActivity.onCreate(popActivity.java:22)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
05-09 21:36:09.820: ERROR/AndroidRuntime(8803): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2627)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
makepopup();
}
public void makepopup(){
LayoutInflater li = LayoutInflater.from(this);
View v1 = li.inflate(R.layout.newpop, null);
popup = new PopupWindow(v1, 400, 240, true);
popup.showAtLocation(v1, Gravity.CENTER, 0, 0);
Button btClose = (Button)v1.findViewById(R.id.close);
btClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(popup != null)
popup.dismiss();
}
});
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en