【问题标题】:java.lang.IllegalStateException: System services not available to Activities before onCreate()java.lang.IllegalStateException:系统服务在 onCreate() 之前对活动不可用
【发布时间】:2014-06-19 22:30:47
【问题描述】:

我遇到了一个异常:

java.lang.IllegalStateException: System services not available to Activities before onCreate()

在 onResume() 中重新初始化 layoutInflater 时:

layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

我正在尝试更新视图翻转器的内容。 谁能建议我对此进行更正以解决异常。

【问题讨论】:

  • 您在onCreate() 之前调用了getSystemService(),但您发布的代码没有显示在哪里。查看异常堆栈跟踪以了解您在哪里调用它。

标签: android viewflipper


【解决方案1】:

看:

public class MyActivity extends Activity {

    // LayoutInflater inflater = (LayoutInflater) context 
    //         .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // NOT CORRECT
    LayoutInflater inflater; // correct

    @Override
    protected void onCreate(Bundle saved) {
        super.onCreate(saved);
        inflater = (LayoutInflater) context 
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // correct
    }
}

【讨论】:

    猜你喜欢
    • 2015-06-12
    • 2011-08-19
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 2013-08-29
    • 1970-01-01
    相关资源
    最近更新 更多