Pregunta

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 ?

¿Fue útil?

Solución

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.

Otros consejos

Usually, you don't need to import R.java. As @Vyger said, most of the time when Eclipse suggests you to import R.java there is something wrong with your R.java... Try to delete and recreate it (See Developing for Android in Eclipse: R.java not regenerating).

This will solve the problem most of the time... If this doesn't work, just import it. It won't harm your application.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top