2

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.

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
  • 1
    You're calling `getSystemService()` before `onCreate()` but the code you posted doesn't show where. See the exception stacktrace to see where you're calling it. – laalto May 03 '14 at 07:50

1 Answers1

8

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
    }
}
Karakuri
  • 38,365
  • 12
  • 84
  • 104