santafebound santafebound - 11 months ago 69
Android Question

AlertDialog.Builder helper class cannot resolve constructor

I've built a helper class to store various AlertDialog types. I thought it would be helpful so that I could call them anywhere in my code. Unfortunately I get an error below at

new AlertDialog.Builder()
. It says
Cannot resolve constructor `Builder()
. How can I get this to work?

public class AlertDialogHelper {

public void showAboutDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder();
builder.setMessage("A weather app made by Martin Erlic")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Ok
AlertDialog alert = builder.create();;


In my activity:

private void showAboutAlertDialog() {
AlertDialogHelper alertDialogHelper = new AlertDialogHelper();

Answer Source

You should pass a Context in the constructor like this:

AlertDialog.Builder builder = new AlertDialog.Builder(context);

From your activity:



public void showAboutDialog(Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);