Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEleni Minadaki
3,687 PointsCannot resolve method'setTitle(java.lang.String)'
Hi!i am on lesson "Build a Weather App",i have write all the code like the lesson but there is an error that i don't know how to fix. The error is:cannot resolve method'setTitle(java.lang.String)'at the 'setTitle' . When i put builder.setTitle all ok but in the lesson ben delete the builder and to him is all ok. Here is my code: package allyouask.com.stormy;
import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.Context; import android.os.Bundle;
/**
-
Created by Eleni on 15/5/2015. */ public class AlertDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(context); .setTitle(context.getString(R.string.error_title)) .setMessage(context.getString(R.string.error_message)) .setPositiveButton(context.getString(R.string.error_ok_button_text), null);
AlertDialog dialog = builder.create(); return dialog;
}
} thanks a lot!
2 Answers
James Simshaw
28,738 PointsHello,
It looks like you forgot to add on the variable name before setTitle. You currently have
.setTitle(context.getString(R.string.error_title))
.setMessage(context.getString(R.string.error_message))
.setPositiveButton(context.getString(R.string.error_ok_button_text), null);
If you change that to
builder.setTitle(context.getString(R.string.error_title))
.setMessage(context.getString(R.string.error_message))
.setPositiveButton(context.getString(R.string.error_ok_button_text), null);
it should get rid of the error you are having.
Eleni Minadaki
3,687 PointsHi James, Thanks a lot,it works!