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

StackOverflow https://stackoverflow.com/questions/23441694

  •  14-07-2023
  •  | 
  •  

I am getting an exception :

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

while reinitializing layoutInflater in onResume() like :

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

I am trying to updatethe The content of view flipper. Can anyone suggest me the corrections in this to resolve the exception.

有帮助吗?

解决方案

Behold:

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
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top