Java 如何让Android中的popupWindow正常工作?

Java 如何让Android中的popupWindow正常工作?,java,android,logging,popup,Java,Android,Logging,Popup,我试图得到一个简单的弹出发生,但一个错误正在返回。错误发生在所提供代码的第四行(最后一行)。有什么建议吗 活动代码 logoutoption = new PopupWindow(); logoutoption.showAtLocation(new LinearLayout(this), Gravity.CENTER, 0, 0); logoutoption.setBackgroundDrawable(getResources().getDrawable(drawable.logoutoption

我试图得到一个简单的弹出发生,但一个错误正在返回。错误发生在所提供代码的第四行(最后一行)。有什么建议吗

活动代码

logoutoption = new PopupWindow();
logoutoption.showAtLocation(new LinearLayout(this), Gravity.CENTER, 0, 0);
logoutoption.setBackgroundDrawable(getResources().getDrawable(drawable.logoutoption_default));
logoutoption.update(100, 50);
日志


替换为以下代码:

LayoutInflater layoutInflater  = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        View popupView = layoutInflater.inflate(R.layout.logoutoption, null);  
        final PopupWindow logoutoption = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
        logoutoption.showAsDropDown(search, 50, -30);
LayoutInflater layoutInflater  = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        View popupView = layoutInflater.inflate(R.layout.logoutoption, null);  
        final PopupWindow logoutoption = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
        logoutoption.showAsDropDown(search, 50, -30);