Java – Prevents importing Android. R

Prevents importing Android. R… here is a solution to the problem.

Prevents importing Android. R

How to prevent Android. Are R packages automatically imported in IntelliJ Idea?

When Idea imports android. R package and you can’t use R class from your project unless you remove “import android. R; This is really annoying to line in your code.

For example, I type:

new ArrayAdapter<String>(getActivity(), android. R.layout.sim

Then press Ctrl+Space and select the first item to complete. My code now looks like this :

new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item_1

Now imports have

import android. R;

When I continued typing, the moment I arrived:

new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item_1, 
                         getResources().getStringArray(R.array.

R.array is actually android. R.array, but that’s not what I expected.

Solution

You can try these options:

imports

Disable the instant addition of explicit imports or will android. R is added to Exclude from Import and Completion.

Related Problems and Solutions