R cannot be resolved to a variable? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-25 04:22:29

问题


I cleaned my project and now I get a "R cannot be resolved to a variable." It was fine before I cleaned it.

I have tried cleaning it again, building the project again, creating a new project and copying all my files over, and I've gone to the Android SDK Manager and installed all the "Android SDK Build-tools" to Install all the options like the other stackoverflow posts have mentioned:

Can anyone suggest anything?

The above picture shows my generated files and lack of an R.java file.

The above picture shows my problems log.


回答1:


Make sure R is in the same package as the file where you want to call it from. (or import the package in the source file)

To change the package of the R file open your App Manifest file and change packge="" to the same package as where your source files are in.




回答2:


maybe you import take other thing

See package main import in your code should be like this example:

import com.mypackageprincipal.R;

other import of R delete only should exist it

and after clean and build your project



来源:https://stackoverflow.com/questions/21768370/r-cannot-be-resolved-to-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!