R cannot be resolved to a variable? [duplicate]

2019-08-29 12:59发布

问题:

This question already has an answer here:

  • R cannot be resolved - Android error 106 answers

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