question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onGetLayoutInflater throws IllegalStateException: A factory has already been set on this LayoutInflater

See original GitHub issue

Hello,

I am targeting API 29, using the AndroidX support library. Minimum target is API 19.

Adding this override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater { val wrappedContext = ViewPumpContextWrapper.wrap(Restring.wrapContext(requireContext())) return wrappedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater }

to my BaseFragment results in the error

java.lang.RuntimeException: Unable to start activity ComponentInfo{******}: java.lang.IllegalStateException: A factory has already been set on this LayoutInflater at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) Caused by: java.lang.IllegalStateException: A factory has already been set on this LayoutInflater at android.view.LayoutInflater.setFactory(LayoutInflater.java:298) at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.setFactory(-ViewPumpLayoutInflater.kt:83) at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.setUpLayoutFactories(-ViewPumpLayoutInflater.kt:76) at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.<init>(-ViewPumpLayoutInflater.kt:35) at dev.b3nedikt.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:25) at dev.b3nedikt.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:22) at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) at dev.b3nedikt.viewpump.ViewPumpContextWrapper.getInflater(ViewPumpContextWrapper.kt) at dev.b3nedikt.viewpump.ViewPumpContextWrapper.getSystemService(ViewPumpContextWrapper.kt:31) at com.shirishanu.apps.ipvc.outgrower.BaseFragment.onGetLayoutInflater(BaseFragment.java:23) at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1484) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187) at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577) at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722) at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:346) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1188) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248) at android.app.Activity.performStart(Activity.java:6679) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2609)

Also I switched to rewword 2.0.1 instead of 2.0.2 because gradle couldn’t find the newer version

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
onebird100commented, Oct 10, 2020

I updated Reword to 2.0.2, removed Philology and removed the above code as you suggested and everything started to work. Thank you.

1reaction
B3nediktcommented, Oct 9, 2020

@onebird100 The issue with 2.0.2 not getting found is fixed, thanks for reporting 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.illegalstateexception: a factory has already been set ...
LayoutInflater.setFactory();. I don't know what is wrong in this code. Can anyone help me in resolving this issue?
Read more >
A factory has already been set on this LayoutInflater Exception
Caused by: java.lang.IllegalStateException: A factory has already been set on this LayoutInflater at android.view.LayoutInflater.
Read more >
fragment/fragment/src/main/java/androidx ... - Google Git
If set this fragment is being removed from its activity. ... throw new IllegalStateException("Fragment already added and state has been saved");.
Read more >
Fragment | Android Developers
onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view ... Returns true if this fragment is added and its state has already been saved ......
Read more >
Source Code for Fragment.java - AndroidX Tech
Set as soon as the // fragment is used in a transaction; cleared after it has been removed // from all transactions. FragmentManager...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found