Not alerting in fragment

Code fmonday.java (PS: To prevent the code from getting too long, I deleted some pieces where the loader is used):

 public class fmonday extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { final int DIALOG_ITEMS = 1; final CharSequence[] items = {"1", "2", "3"}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fmonday, container, false); Button button12 = (Button) rootView.findViewById(R.id.button12); button12.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().showDialog(DIALOG_ITEMS); } }); } @Override //Здесь ошибка protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ITEMS: AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); adb.setTitle("Adding class"); adb.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { Toast.makeText(getActivity().getApplicationContext(), "Your choice: " + items[item], Toast.LENGTH_SHORT).show(); } }); adb.setCancelable(false); return adb.create(); default: return null; } } 

logcat:

Error: (88, 5) error method

How to solve this problem?

  • one
    Replace the parent class Fragment with DialogFragment - Andrey Kasyanov
  • one
    There is no onCreateDialog method in the Fragment base class. He is in the class DialogFragment. - Sergey Gornostaev
  • @Andrey Kasyanov, @SergeyGornostaev, changed the parent class to Dialog Fragment , the error remained the same. Did not help - ABL

1 answer 1

You did not correctly specify the method signature (return type, method name, argument list (their number, order and types)) and created a new method that does not exist in the class, after which you said that this method supposedly exists in the superclass .
The IDE noticed your mistake and said so.

At this stage, you had to look into the docks and make sure that the DialogFragment class DialogFragment not have the Dialog onCreateDialog(int id) method.

But there is a Dialog onCreateDialog(Bundle savedInstanceState)

So you made a mistake in the argument list of the method, namely in the type of the argument, by writing int instead of Bundle .