-7
....    

@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)

任何想法如何解决它?

4

1 回答 1

2

唯一被破坏的是你的代码。修复将是避免在 onCreate() 完成之前访问系统服务,否则还没有对活动对象进行设置,因此您面临自我解释的原因异常。

于 2013-02-12T16:22:21.870 回答