ViewPager.setAdapter throws IllegalArgumentException in Android
java.lang.IllegalArgumentException
at androidx.core.util.Preconditions.checkArgument(Preconditions.java:38)
at androidx.viewpager2.adapter.FragmentStateAdapter.onAttachedToRecyclerView(FragmentStateAdapter.java:132)
at androidx.recyclerview.widget.RecyclerView.setAdapterInternal(RecyclerView.java:1243)
at androidx.recyclerview.widget.RecyclerView.setAdapter(RecyclerView.java:1194)
at androidx.viewpager2.widget.ViewPager2.setAdapter(ViewPager2.java:461)
at net.twobeone.pink.fragments.MainFragment.activityInit(MainFragment.kt:58)
at net.twobeone.pink.fragments.MainFragment.onViewCreated(MainFragment.kt:49)
at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3128)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:552)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1890)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1823)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1760)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:547)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Solution :
Initialize ViewPagerAdapter in onCreateView.
Wrong Example:
class MainFragment : BaseFragment<FragmentMainBinding>() {
private val viewPagerAdapter : ViewPagerAdapter by lazy { ExampleViewPagerAdapter(this) }
}
댓글 없음:
댓글 쓰기