Android Studio 2.1, Java V8 Update 91, Gradle 2.1.0 .
I know that this questions has been asked many times here, but none of the recommendation solutions works out.
Maybe the error may cause for the tools, trying install Android SDK Build Tools from Tools > Android > SDK Manager. or maybe this error can be caused by adding an activity to a namespace that is different to the root, you can trying >>Import com.example.MyApplication.R; or your also can clean o rebuild your project in Build > Clean Project or Build > Rebuild Project