我已经为忘记密码做了一个弹出警报..我必须拨打api电话忘记密码,我已经做到了,一切都运行良好,但事情就是我想打电话给api来电忘记密码点击那个弹出警报的“发送”按钮。但是它显示一个错误..这个asynctask在这里无法访问..!
我的代码如下:
login.java
package com.epe.yehki.ui;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.epe.yehki.backend.BackendAPIService;
import com.epe.yehki.backend.BackendAPIService;
import com.epe.yehki.backend.LoginAPI;
import com.epe.yehki.modelclasses.LoginResponceModelClass;
import com.epe.yehki.servercommunication.AsyncTaskCompleteListener;
import com.epe.yehki.servercommunication.MyAsyncTask;
import com.epe.yehki.servercommunication.YehkiNameValuePairs;
import com.epe.yehki.uc.Menu;
import com.epe.yehki.util.Const;
import com.epe.yehki.util.Pref;
import com.epe.yehki.util.Utils;
import com.example.yehki.R;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class LoginActivity extends Activity {
public LoginAPI loginAPI;
private EditText email;
private EditText password;
private TextView signup;
private TextView forgot;
private Button login;
private ImageView ivRemember;
public com.epe.yehki.uc.Menu loginmenu;
private ProgressDialog progressDialog;
public boolean flag = false;
private ProgressDialog pDialog;
String status;
int flag1;
static EditText et_email;
private EditText popEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
email = (EditText) findViewById(R.id.et_username);
password = (EditText) findViewById(R.id.et_pwd);
login = (Button) findViewById(R.id.btn_login);
ivRemember = (ImageView) findViewById(R.id.iv_remember);
loginmenu = (Menu) findViewById(R.id.menuLogin);
signup = (TextView) findViewById(R.id.tv_sign_up);
forgot = (TextView) findViewById(R.id.tv_fgt_pwd);
loginmenu.setSelectedTab(1);
// CREATE ACCOUNT CLICK EVENT..!!
signup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(LoginActivity.this, RegistrationActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();
}
});
// REMEMBER ME CLICK EVENT...!
ivRemember.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (flag) {
ivRemember.setBackgroundResource(R.drawable.untic);
Pref.setValue(LoginActivity.this, Const.PREF_REMEMBER_ME, "0");
flag = false;
} else {
System.out.println("checkbox check");
ivRemember.setBackgroundResource(R.drawable.tic);
Pref.setValue(LoginActivity.this, Const.PREF_REMEMBER_ME, "1");
flag = true;
}
}
});
// LOGIN CLICHK EVENT...
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!email.getText().toString().equals("") && email.getText().toString() != null) {
if ((!password.getText().toString().equals("") && password.getText().toString() != null)) {
if (Utils.isOnline(LoginActivity.this)) {
// Call AsyncTask For loginUser.
callAsyncLoginUser();
}
} else {
validation(getResources().getString(R.string.msg_password));
password.requestFocus();
}
} else {
validation(getResources().getString(R.string.msg_enter_email));
email.requestFocus();
}
}
});
// FORGOT PASSWORD....!!!
}
void validation(String msg) {
Utils.showCustomeAlertValidation(LoginActivity.this, msg, "Alert", "OK");
}
// RESPONSE lISTENER...................!!
// *************************************************************************************************
/**
* CallAsyncTask for getting responc of countryList.
*/
private void callAsyncLoginUser() {
ArrayList<NameValuePair> argumentsList = YehkiNameValuePairs.getLoginNVPair(email.getText().toString(), password.getText().toString());
MyAsyncTask loginAsyncTask = new MyAsyncTask(this, Const.API_LOGIN, argumentsList);
loginAsyncTask.execute();
loginAsyncTask.setOnResultsListener(new AsyncTaskCompleteListener() {
@Override
public void onResultsSucceeded(String result, int asyncTaskNo) {
Log.i("RegestrationActivity", "Result ================= " + result);
LoginResponceModelClass userLoginResponce = parseUserLoginResponce(result);
if (userLoginResponce != null) {
if (userLoginResponce.status.equalsIgnoreCase("success")) {
Intent i = new Intent(LoginActivity.this, HomeActivity.class);
Pref.setValue(LoginActivity.this, Const.PREF_CUSTOMER_ID, userLoginResponce.customer.get(0).customer_id);
Pref.setValue(LoginActivity.this, Const.PREF_CUSTOMER_NAME, userLoginResponce.customer.get(0).customer_name);
Pref.setValue(LoginActivity.this, Const.PREF_USER_EMAIL, userLoginResponce.customer.get(0).email);
// i.putExtra("mail",
// userLoginResponce.customer.get(0).email);
startActivity(i);
finish();
}
}
}
});
}
// **********************************************************************************************************
/**
* Function for Storing the data into model class using gson library.
*
* @param result
* @return
*/
private LoginResponceModelClass parseUserLoginResponce(String result) {
try {
GsonBuilder gsonb = new GsonBuilder();
Gson gson = gsonb.create();
LoginResponceModelClass responce = gson.fromJson(result, LoginResponceModelClass.class);
return responce;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* FORGOT PASSWORD API CALL............!!!!
*
*
*/
// FORGOT PASSWORD POPUP...!!!
public static void showCustomeAlertValidation(final Context context, String leftButton) {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.forgot_password);
dialog.setCancelable(true);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
et_email = (EditText) dialog.findViewById(R.id.et_mail);
final Button send = (Button) dialog.findViewById(R.id.btn_send);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new ForgotPassword().execute();
dialog.dismiss();
}
});
dialog.show();
}
/**
* FORGOT PASSWORD API CALL
*/
public class ForgotPassword extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
System.out.println("==========inside preexecute===================");
}
@Override
protected Void doInBackground(Void... arg0) {
String forgetURL = Const.API_FORGOT_PASSWORD + "?email=" + et_email.getText().toString();
BackendAPIService sh = new BackendAPIService();
System.out.println(":::::::::::::forget url:::::::::::;" + forgetURL);
String jsonStr = sh.makeServiceCall(forgetURL, BackendAPIService.GET);
Log.d("Response: ", "> " + jsonStr);
System.out.println("=============MY RESPONSE==========" + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
if (jsonObj.has(Const.TAG_STATUS)) {
status = jsonObj.getString(Const.TAG_STATUS);
{
if (status.equalsIgnoreCase("success")) {
flag1 = 1;
} else {
flag1 = 2;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
if (flag1 == 1) {
Toast.makeText(LoginActivity.this, "Forgot password link has been sent to your mail", Toast.LENGTH_SHORT).show();
finish();
} else {
Utils.showCustomeAlertValidation(LoginActivity.this, "Invalid Credentials", "Yehki", "OK");
}
}
}
}
答案 0 :(得分:0)
我认为您从静态方法调用非静态方法public class ForgotPasswor
d。
从static
删除showCustomeAlertValidation
可以解决您的问题。