....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
done = true;
}
...
public class addcontacts extends ListActivity {
protected void onCreate() {
}
protected void execute(final Boolean success) {
if (done) {
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
}
}
}
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
...
}
@Override
protected void onPostExecute(final Boolean success) {
setContentView(R.layout.main);
ac = new addcontacts();
ac.execute(true);
}
...
public class getcontacts extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
...
listItems.add(json_data.getString("login") + " " + derp);
...
}
...
}
@Override
protected void onPostExecute(final Boolean success) {
getc = null;
//showProgress(false);
adapter.notifyDataSetChanged();
}
运行时错误:
02-12 15:59:35.274: E/AndroidRuntime(1308): FATAL EXCEPTION: main
02-12 15:59:35.274: E/AndroidRuntime(1308): java.lang.IllegalStateException: System services not available to Activities before onCreate()
02-12 15:59:35.274: E/AndroidRuntime(1308): at android.app.Activity.getSystemService(Activity.java:3989)
02-12 15:59:35.274: E/AndroidRuntime(1308): at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
02-12 15:59:35.274: E/AndroidRuntime(1308): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
任何想法如何解决它?