私はAndroidプログラミングに不慣れで、もちろん、仲間のStackoverflowユーザーの助けを借りて概念を学ぼうとしています。
私がやろうとしていること:ログインページから、サーバー上にあるjsonファイルからログイン資格情報を取得しようとしています。jsonファイルを解析し、ログインクレデンシャルを確認した後、アプリの次のページ(ホーム)への新しいインテントを開始しています。
問題:stackoverflowユーザーの提案に従って、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) {
}
}
解決策を探しています。前もって感謝します。