我是新来的Android编程和尝试学习的概念,当然在我的同胞Stackoverflow用户的帮助。Android Intent中AsyncTask类给出的错误
我在做什么:从登录页面,我试图从位于服务器上的json文件中获取登录凭证。解析json文件并验证登录凭据后,我开始了一个新的意图到我的应用程序(Home)的下一页。
问题:我已经成功做了所有networkings操作和分析使用的AsyncTask后台线程,通过计算器用户的建议。但是,验证登录凭证后,当我尝试在AsyncTask类的postExecute方法内启动新的意图时,它会给我以下错误。请提出什么是错的。
错误:
The constructor Intent(LoginActivity.RetreiveDataAsynctask, Class<HomeActivity>) is undefined
错误行:
Intent intent = new Intent(this,HomeActivity.class);
代码:
private class RetreiveDataAsynctask extends AsyncTask<String,Void,JSONObject> {
@Override
protected JSONObject doInBackground(String... loginURL) {
JSONObject obj = getJSONfromURL(loginURL[0]);
return obj;
}
@Override
protected void onPostExecute(JSONObject obj) {
//Do all ur UI related stuff as this will be executing in ui thread
super.onPostExecute(obj);
TextView loginStatus = (TextView) findViewById(R.id.login);
TextView userId = (TextView) findViewById(R.id.userId);
//if login successful, then go to the next page.
try {
loginStatus.setText(obj.getString("LOGIN"));
userId.setText(obj.getString("userId"));
AlertDialog.Builder adb = new AlertDialog.Builder(
LoginActivity.this);
adb.setTitle("Login Service");
adb.setPositiveButton("Ok", null);
if(obj.getString("LOGIN").equalsIgnoreCase("TRUE") && !obj.getString("userId").equalsIgnoreCase("")){
//call next page
adb.setMessage("Login Success...!!");
Intent intent = new Intent(this,HomeActivity.class); **//THIS LINE SHOWS ERROR**
startActivity(intent);
}else{//login unsuccessful
adb.setMessage("Login Failed...!!");
}
adb.show();
} catch (JSONException e) {
Log.e("log_tag", "JSONException "+e.toString());
}
}
@Override
protected void onPreExecute() {
TextView loginStatus = (TextView) findViewById(R.id.login);
TextView userId = (TextView) findViewById(R.id.userId);
loginStatus.setText("Not Fetched");
userId.setText("Not Fetched");
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
寻找一个SOLUT离子。提前致谢。
THX这么快回复!完美工作!选择这个作为正确的答案。 Thx再次! – 2013-02-14 06:49:21
乐意帮忙..!快乐编码..! – user370305 2013-02-14 06:49:52