Activity continues in a class, can not let onCreate and constructors simultaneously emerge? ?
If not, why not?
If so, why is there an error?
12-19 02:33:10.343: E / AndroidRuntime (10398): FATAL EXCEPTION: main
12-19 02:33:10.343: E / AndroidRuntime (10398): java.lang.IllegalStateException: System services not available to Activities before onCreate ()
12-19 02:33:10.343: E / AndroidRuntime (10398): at android.app.Activity.getSystemService (Activity.java: 3989)
How should solve?
Reply:
Never tried to use the constructor
Reply:
1 constructor java Lane, oncreate is android in the callback function, the two are not directly linked.
2 You put these two functions you call code stickers to help you look.
Reply:
I tried it can write constructor, the constructor I did not do anything wrong tips are: probably you do in the constructor method to wait until after it oncreate
Reply:
java.lang.IllegalStateException: System services not available to Activities before onCreate ()
This error is not enough detail to say it
Meaning that in the constructor (that is, before onCreate) Activity in calling some methods, but because onCreate has not been performed, so the System services are ineffective, while calling System services are Activity.java in android.app.Activity.getSystemService
Reply:
In FirstActivity, I want to generate SecondActivity object reference
SecondActivitymode = new SecondActivity (this);
mode.showModeWindow ();
In SecondActivity code:
public SecondActivity (Context mContext) {
this.context = mContext;
initModeWindow ();
}
private void initModeWindow () {
layoutInflater = LayoutInflater.from (context);
. / / LayoutInflater layoutInflater = (LayoutInflater) (this) getSystemService (LAYOUT_INFLATER_SERVICE);
View popView = layoutInflater.inflate (R.layout.short_popupwindow_layout, null);
lvModeWindow = (ListView) popView.findViewById (R.id.short_popuwindow_list_id);
arrModeList = context.getResources () getStringArray (R.array.screen_mode);.
popuWindowAdapter = new ArrayAdapter(this, R.layout.spinner_own_model, arrModeList);
popWindow = new PopupWindow (popView, POPUPWINDOW_WIDTH, LayoutParams.WRAP_CONTENT);
lvPopuWindow.setAdapter (popuWindowAdapter);
popWindow.setOutsideTouchable (true);
popWindow.setFocusable (true);
popWindow.setBackgroundDrawable (new BitmapDrawable ());
popWindow.update ();
if (null! = modeWindow) {
modeWindow.dismiss ();
return;
}
}
public void showModeWindow () {
View homeView = layoutInflater.inflate (R.layout.home_layout, null);
popWindow.showAtLocation (homeView, Gravity.RIGHT | Gravity.TOP, POPUP_OFFSET_X, POPUP_OFFSET_Y);
}
protected void onCreate (Bundle savedInstanceState) {
/ / ...
}
Reply:
Code 5L, see if there is a problem?
Reply:
However, my constructor and onCreate almost no contact ...
Reply:
Constructor and onCreate certainly no contact, they only during program execution priorities, but rather the process you use the data later in the process in the beginning, you can not go wrong
Reply:
Ah, thank you for the warm solution. I myself writing code, some variables confuse what messed up.
Reply:
Construction method is to run, but usually not so used.
Visually your program should be the first line of the fault
11popuWindowAdapter = new ArrayAdapter
In this line, you should refer to this is SecondActivity.this At the moment, SecondActivity not executed onCreat () method, which is the error message said System services not available to Activities before onCreate (). I suggest you put that all this changed context, is that you passed in the constructor inside that context object (this.context) try.
Reply:
You rewrite oncreate method, which has consequently not, it certainly incorrect report. Visual methods to oncreate deleted can be resolved.
Your landlord is how to solve ah?
Reply:
Citie pretty good, I also encountered the same problem, and we have not found a solution, and now some understand.
No comments:
Post a Comment