0

An error on my app's dialog fragment causes my app to crash. I recently used Roman Nurik's wizard pager and now, am experiencing these. Was there something wrong with how I used the codes? I am new to android and am finding a hard time what the message below meant.

Fragments should be static such that they can be re-instantiated by the system, and anonymous classes are not static less... (⌘F1)

Inspection info: From the Fragment documentation: Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().

Issue id: ValidFragment

mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
                DialogFragment dg = new DialogFragment() {
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new AlertDialog.Builder(getActivity())
                                .setMessage(R.string.submit_confirm_message)
                                .setPositiveButton(R.string.submit_confirm_button, null)
                                .setNegativeButton(android.R.string.cancel, null)
                                .create();
                    }
                };
                dg.show(getSupportFragmentManager(), "place_order_dialog");
            } else {
                if (mEditingAfterReview) {
                    mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
                } else {
                    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                }
            }
        }
    });
   

I need to understand what I did wrong and how I can fix this moving forward. [![enter image description here][1]][1]

Community
  • 1
  • 1
Wendz
  • 31
  • 6
  • Stacktrace or it didn't happen! – hardartcore Jan 28 '19 at 16:50
  • You're creating an anonymous `DialogFragment` subclass. You can't do that with `Fragment`s, for the reasons explained in the linked duplicates. Create a regular subclass of `DialogFragment` where you override `onCreateDialog()` – e.g., `public MyDialogFragment extends DialogFragment` – and use that instead. – Mike M. Jan 28 '19 at 17:07
  • @hardartcore -- my log cat has this message - "Unable to start activity ComponentInfo{widevalue.com.widevalueautoinc/widevalue.com.widevalueautoinc.ActivityVehicle}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.example.android.wizardpager.wizard.ui.StepPagerStrip" – Wendz Jan 28 '19 at 17:16
  • 1
    That's a different problem. – Mike M. Jan 28 '19 at 17:18

0 Answers0