我是新來的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