我想在 android 中显示一个 popupWindow 我做了以下操作:
public class MyPopUp extends PopupWindow {
private View view;
private Context context;
public MyPopUp (Context context)
{
super(context);
this.context = context;
View myView = new myView(context);
this.setContentView(myView );
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
}
public void showPopUp(){
view = new View(context);
this.showAtLocation(view, Gravity.CENTER, 0, 0);
}
}
这条线上有一个例外
this.showAtLocation(view, Gravity.CENTER, 0, 0);
02-02 09:13:31.456: ERROR/AndroidRuntime(458): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.popup.mypopup/com.popup.mypopup.Android_2_Activity}: java.lang.NullPointerException
当调用 showPopUp 时