cannot resolve symbol R Android DialogFragment

I would like create an AlertDialog with a custom XML layout, but in my class I can't found R variable, why ?

This is my class :

public class NewTestDialogFragment extends DialogFragment {

    public NewTestDialogFragment(){
        super();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        builder.setView(inflater.inflate(R.layout.name_dialog, null));

        builder.setTitle("Test");

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dismiss();
            }
        });

        return builder.create();
    }
}

R is not found. If I import R, the application crash..

Answers


You may have changed your application package name in manifest file. Check it then import, clean and then build.


Need Your Help

What is Object Scope in Oop?

c++ class oop object

Hi I read this definition on internet..