Search code examples
androidimportr.java-file

is importing R.java correct?


I know this question might have been asked a thousand times on StackOverflow, but I have a precise question : When I have the problem of "R cannot be resolved to a variable", should I import the R of the package ? I know that eclipse suggests it and doing it solves the problem but is that correct to have the import of R in the class ?


Solution

  • Yes. All of your resource ids are compiled into R.java. If you do not import com.mypackage.R then any references such as R.id.textview will not resolve.