Android异步任务错误

时间:2013-08-16 07:29:41

标签: android android-asynctask

我是Android的新手,并使用AsyncTask练习短信应用。当我在模拟器应用程序上运行它时无法启动。发生错误致命异常AsyncTAsk#1。 我正在尝试使用AsyncTask填充收件箱。 Plz帮助。

public class Welcome extends Activity implements OnClickListener{
ListView smslist;
Cursor cursor;
Context context;
SimpleCursorAdapter mcursor;
Button button;
private static final String TAG = "ADA CLASS";
private static final String TAG1 = "ADAPTE CLASS";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
    button= (Button) findViewById(R.id.button1);
    button.setOnClickListener(this);
    smslist = (ListView) findViewById(R.id.listView1);

    new thrd().execute(context);
}

    class thrd extends AsyncTask<Context,Void,SimpleCursorAdapter>{
        String [] a= {"address", "body","date"};
        int[] b={R.id.textView1,R.id.textView2,R.id.textView4};
        @Override
        protected SimpleCursorAdapter doInBackground(Context... params) {
            Context c= params[0];
            Uri smsuri = Uri.parse("content://sms/inbox");
            cursor=getContentResolver().query(smsuri, null, null ,null,null);
            mcursor=new SimpleCursorAdapter(c, R.layout.row, cursor, a,b, 0);
            return mcursor;
        }

        @Override
        protected void onPostExecute(SimpleCursorAdapter result) {
            smslist.setAdapter(result);
        }
    }

@Override
public void onClick(View v) {
    Intent intent=new Intent(this, SendSMS.class);
    startActivity(intent);

}

}

1 个答案:

答案 0 :(得分:0)

请检查上下文的值。

context = getApplicationContext();