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

标签 android viewflipper

我遇到异常:

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/

相关文章:

android - 使用带有返回堆栈的 fragment 时如何减少内存使用?

android - flutter 。屏幕上的空白

android - 从 Android 应用程序打开 Facebook 页面?

android - 当文本太长时防止按钮调整大小?

android - 我如何在Android中制作动态翻转屏幕(如iPhone)

android - Graphical Layout 显示ViewFlipper 的第一个 View ,如何查看其他 View ?

android - 如何在 Android 中编写动态幻灯片

Android分配变量时内存不足

Android-在两个图像之间翻转水平动画

android - 图像在 viewflipper 中居中