0

I am having an issue after placing my fragments into a sub directory with isValidFragment function.

All activities and fragments were previously under:

  • app/src/main/java/com/myproject/settings/

皇冠hg0088代理网址They are now located here:

  • app/src/main/java/com/myproject/settings/fragments/

After the move and placing import com.myproject.settings.fragments.*; in the SettingsActivity.java that is still located under settings/, isValidFragment is still receiving com.myproject.settings.GeneralSettingsFragment.. While my call to GeneralSettingsFragment.class.getName() is returning the correct com.myproject.settings.fragments.GeneralSettingsFragment.

See isValidFragment below:

    @Override
    protected boolean isValidFragment(String fragmentName) {
        return PreferenceFragment.class.getName().equals(fragmentName)
                || GeneralSettingsFragment.class.getName().equals(fragmentName);
    }

The error I receive:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproject.settings/com.myproject.settings.SettingsActivity}: java.lang.IllegalArgumentException: Invalid fragment for this activity: com.myproject.settings.GeneralSettingsFragment

皇冠hg0088代理网址I have cleaned project and manually deleted build folder and rebuilt with no luck. Any guidance is appreciated.

0

If only to my future self..

Using Android Studio none of these worked :

  • rebuild
  • File->Invalidate Caches
  • Delete .idea/ folder and resync project with gradle

What needed to be done was using the gradle menu ( or command line ) use app->Tasks->build->build. This uncovered many issues with renaming in the .xml files where they weren't updated with the correct path ( com.myproject.settings.fragments.<fragmentName> ).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy皇冠hg0088代理网址

Not the answer you're looking for? Browse other questions tagged or ask your own question.