我是 android 新手,正在使用 AsyncTask 练习一个短信应用程序。当我在模拟器应用程序上运行它时无法启动。发生错误致命异常 AsyncTAsk #1。我正在尝试使用 AsyncTask 填写收件箱。请帮助。
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);
}
}