1.构造函数是java里的,oncreate是android里的回调函数,两者没有直接联系。2.你把你调用这两个函数的代码贴出来,帮你看看。

解决方案 »

  1.   

    我试了一下可以写构造函数的,我的构造函数里什么事情也没做,错误提示是:可能是你在构造函数做的事情要等到oncreate方法之后吧
      

  2.   

    java.lang.IllegalStateException: System services not available to Activities before onCreate()这个错误说的还不够详细吗
    意思是在构造函数(就是onCreate之前)里调用了一些Activity的方法,但是由于onCreate还没有执行过,所以System services 是无效的,而调用System services 是在Activity.java里android.app.Activity.getSystemService
      

  3.   

    在FirstActivity中,我要生成SecondActivity对象的引用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) {
    //...

      

  4.   

    但是,我的构造函数和onCreate几乎是没有任何联系的...
      

  5.   

    构造函数和onCreate当然没有任何联系,它们只是程序执行过程中的先后次序而已,而你在开始的过程中使用了后来过程的数据,能不出错吗
      

  6.   

    构造方法是运行的,只是通常不这么用。
    目测你的程序应该是第11行出的错
    popuWindowAdapter = new ArrayAdapter<String>(this, R.layout.spinner_own_model, arrModeList);
    在这一行中,你的this应该指的的是SecondActivity.this 而在此时,SecondActivity还没有执行过onCreat()方法,也就是报错信息所说的System services not available to Activities before onCreate()。所有建议你把那个this换成context,就是你在构造方法里面传进来的那个context对象(this.context)试试。
      

  7.   


    你重写了oncreate方法,里面却啥都没有,它当然报错了。目测把oncreate方法删掉可以解决。楼主你是怎么解决的啊?