Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Resolve Fragmentation Error in Android Application?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 583
    Answer it

    I am trying to create a tab layout . So,I am trying to inject an instance of FragmentManager to pass into the constructor of the ViewPagerAdapter. While doing this I'm getting this Error:

    Error:(16, 10) error: android.app.FragmentManager cannot be provided without an @Provides- or @Produces-annotated method. android.app.FragmentManager is injected at example.XYZ.com.tabsdagger.MainActivity.fragmentManager example.XYZ.com.tabsdagger

     

    AppModule:
    @Module
    public abstract class AppModule {
        @ContributesAndroidInjector(modules = MainActivityModule.class)
         abstract MainActivity mainActivity();
        @Provides
        @Singleton
        static Context getContext(Application application){
            return application.getApplicationContext();
        }

    }

    AppComponent:
    @Singleton
    @Component(modules = {MainActivityModule.class, AppModule.class})
    public interface AppComponent {
        void inject(MainActivity mainActivity);

        @Component.Builder
        interface Builder {
            AppComponent build();

            @BindsInstance
            Builder buildapp(Application application);
            @BindsInstance
            Builder mainActivityBuilder(MainActivity mainActivity);
        }
    }
    MainActivityModule:
    <pre>@Module
    public abstract class MainActivityModule {

        @Provides
        static FragmentManager getFragmentManager(MainActivity mainActivity) {
            return mainActivity.getSupportFragmentManager();
        }
    }

    MyTabApplication:
    public class MyTabApplication extends Application {
        @Inject
        MainActivity mainActivity;
        private static AppComponent appComponent;
        public static AppComponent getAppComponent(){
            return appComponent;
        }
        @Override
        public void onCreate() {
            super.onCreate();
            appComponent=buildMyComponent();
        }

        private AppComponent buildMyComponent() {
            return DaggerAppComponent.builder().buildapp(this).mainActivityBuilder(new MainActivity()).build();
        }
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: