我得到一个例外:
java.lang.IllegalStateException: System services not available to Activities before onCreate()
重新初始化onResume()中的layoutInflater,如:
layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
我正在尝试更新视图鳍状肢的内容。 任何人都可以建议我在此更正以解决异常。
答案 0 :(得分:8)
看哪:
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
}
}