80,469
社区成员




12-19 02:33:10.343: E/AndroidRuntime(10398): FATAL EXCEPTION: main
12-19 02:33:10.343: E/AndroidRuntime(10398): java.lang.IllegalStateException: System services not available to Activities before onCreate()
12-19 02:33:10.343: E/AndroidRuntime(10398): at android.app.Activity.getSystemService(Activity.java:3989)
SecondActivitymode = new SecondActivity(this);
mode.showModeWindow();
在SecondActivity中代码:
public SecondActivity(Context mContext) {
this.context = mContext;
initModeWindow();
}
private void initModeWindow() {
layoutInflater = LayoutInflater.from(context);
// LayoutInflater layoutInflater = (LayoutInflater) (this).getSystemService(LAYOUT_INFLATER_SERVICE);
View popView = layoutInflater.inflate(R.layout.short_popupwindow_layout, null);
lvModeWindow = (ListView) popView.findViewById(R.id.short_popuwindow_list_id);
arrModeList = context.getResources().getStringArray(R.array.screen_mode);
popuWindowAdapter = new ArrayAdapter<String>(this, R.layout.spinner_own_model, arrModeList);
popWindow = new PopupWindow(popView, POPUPWINDOW_WIDTH, LayoutParams.WRAP_CONTENT);
lvPopuWindow.setAdapter(popuWindowAdapter);
popWindow.setOutsideTouchable(true);
popWindow.setFocusable(true);
popWindow.setBackgroundDrawable(new BitmapDrawable());
popWindow.update();
if(null != modeWindow) {
modeWindow.dismiss();
return;
}
}
public void showModeWindow(){
View homeView = layoutInflater.inflate(R.layout.home_layout, null);
popWindow.showAtLocation(homeView, Gravity.RIGHT | Gravity.TOP, POPUP_OFFSET_X, POPUP_OFFSET_Y);
}
protected void onCreate(Bundle savedInstanceState) {
//...
}