Reputation: 126
i need some help trying to figure this out, it worked previously but after changing a couple of codes, it might be an issue. Maybe because i change over from fragment to activities.
btnRegister.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
if (name.getText().toString().equals("") || email.getText().toString().equals("") || pw.getText().toString().equals("")) {
android.app.AlertDialog.Builder alertDialogBuilder =
new android.app.AlertDialog.Builder(Register.this);
alertDialogBuilder.setTitle("Something went wrong");
alertDialogBuilder.setMessage("Please check and fill in all the fields");
alertDialogBuilder.setPositiveButton("Ok", new android.content.DialogInterface.OnClickListener() {
public void onClick(android.content.DialogInterface dialog, int which) {
dialog.dismiss();
}
});
//displaying of alert dialog
android.app.AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
//checking pw and confirm pw
else if (!pw.getText().toString().equals(pwConf.getText().toString())) {
android.app.AlertDialog.Builder alertDialogBuilder =
new android.app.AlertDialog.Builder(Register.this);
alertDialogBuilder.setTitle("Something went wrong");
alertDialogBuilder.setMessage("Your passwords are not matching");
alertDialogBuilder.setPositiveButton("Ok", new android.content.DialogInterface.OnClickListener() {
public void onClick(android.content.DialogInterface dialog, int which) {
dialog.dismiss();
pw.setText("");
pwConf.setText("");
}
});
android.app.AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
else{
BackgroundTask backgroundTask = new BackgroundTask();
backgroundTask.execute("register", name.getText().toString(), email.getText().toString(), pw.getText().toString());
}
}
});
yep so it's at the setting of Background task = new Background task, it is showing an error stating "Background task (context) in Background task cannot be applied to ().
Here's my backgroundtask class.
public class BackgroundTask extends android.os.AsyncTask<String, Void, String>{
android.content.Context ctx;
android.app.Activity activity;
android.app.ProgressDialog progressDialog;
String register_url = "http://10.0.2.2/mydb/register.php";
android.app.AlertDialog.Builder builder;
public BackgroundTask(android.content.Context ctx) {
this.ctx = ctx;
activity = (android.app.Activity)ctx;
}
Upvotes: 0
Views: 831
Reputation: 29320
Your constructor requires a Context. Change
BackgroundTask backgroundTask = new BackgroundTask();
to
BackgroundTask backgroundTask = new BackgroundTask(getActivity());
Upvotes: 2