gpt4 book ai didi

android - java.lang.IllegalStateException : System services not available to Activities before onCreate() 错误

转载 作者:太空狗 更新时间:2023-10-29 15:53:18 27 4
gpt4 key购买 nike

我遇到异常:

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

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

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

我正在尝试更新 view flipper 的内容。任何人都可以建议我对此进行更正以解决异常。

最佳答案

看:

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
}
}

关于android - java.lang.IllegalStateException : System services not available to Activities before onCreate() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23441694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com