问题
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.
回答1:
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
}
}
来源:https://stackoverflow.com/questions/23441694/java-lang-illegalstateexception-system-services-not-available-to-activities-bef