skip to Main Content

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


  1. 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 of R.layout but most the time it because of non-existing ids like following example:

    int value = 999;
    Toast.makeText(context, value, Toast.LENGTH_SHORT).show();
    

    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:

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        StringBuilder sb = new StringBuilder();
        Class clazz = R.class;
        Class[] classes = clazz.getDeclaredClasses();
        for(int m=0; m < classes.length; ++m) {
            sb.append("Class name: " + classes[m].getSimpleName() + "n");
            Field[] fields = classes[m].getDeclaredFields();
            sb.append("Number of fields: " + fields.length + "n");
            try {
                for(int n=0; n < fields.length; ++n)
                    sb.append(String.format("Field[%d]: %s=0x%08xn", n+1, fields[n].getName(), fields[n].getInt(fields[n])));
            } catch(Exception e) {}
        }
        Log.d("TAG", sb.toString());
        //Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();
    }
    

    enter image description here

    Login or Signup to reply.
  2. 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.

    every class or fragment has it's layout to tell android studio how to show the code. It makes the whole design there

    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
    enter image description here

    I hope that is going to help you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search