import android.R in Eclipse : Why?

This is not a bug. There are a few instances where android.R can be helpful and solve problems.

android.R is an R.java file like the one you have in your own projects. The one in your projects (your.packagename.R) holds references to the resources you have under your /res folder like layouts, drawables, XML files, raw files, strings etc.

On the other hand, the android.R file holds references to certain default resources that Android has inbuilt, like simple_list_item_1.

Eclipse suggests this and auto imports this sometimes as if your project’s R file hasn’t been generated due to an XML error or something, your code will be referencing a file that doesn’t exist. By importing android.R, eclipse makes sure your code references a class that exists. However, android.R is unlikely to have the same resources you did, and this will raise another set of errors.

Leave a Comment