Tried to make it short but have to explain in detail. I have one small project where I have one activity and multiple fragments. While launching, first fragment added and works fine. After that when I navigated to another fragment by using replace, another fragment opens but it does not display any UI at all. When i debugged it, then while inflating it says Resource not found
without any extra details. While in log it’s Invalid ID XXXXXXXXX
where XXXXXXXXX
is the id number but I am not able to find which id it is because as there is no R file in android studio.
Also tried to use analyze apk
but did not find any id with that number there as well with no luck.
Also tried clean build, with no luck.
Please do help here.
2
Answers
I’ve seen this kind of errors many times here in Stack Overflow. It may caused by passing an invalid/wrong resource id e.g.
R.id
instead ofR.layout
but most the time it because of non-existing ids like following example:Even though the code compiles just fine, but as you already know it will throw a RuntimeException.
Anyway, you can check your ids with the following code:
looks for me like your app doesn’t have a layout file. It only shows something if you have a Layout file that tells Android Studio how the fragment is supposed to look like. Make in the Layout folder a document for it and connect it to the fragment.
you can see I have for every single of the classes/Fragnments a Layout file that tells Android Studio how to show every part of the class, shape and color of buttons, TextViews and more.
You then connect it to the class so the class knows where it’s layout is
I hope that is going to help you