문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top