Why do I need to import an R class when I use a resource in a package without root?

Whenever I want to use any resource element in a non-root package, I need to import my own R class(not the Android R class). For instance,

Root package com.example.testand fileMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

No need to import R class.

When I create another package com.example.test.somethingand the new class is there Something.java, I need to import my ownR.class

import com.example.test.R;

//...other code...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

This happens automatically when I move the Java file from the root to a package without root.

Why is this so important?

+3
source share
1 answer

R com.example.test - . , , .

+8

All Articles