I would like to fix this error
R cannot be resolved to a variable
I looked up many answers, but I could not get the right one;
Before you try anything else, please check that your package declaration in your AndroidManifest.xml
file matches the actual package name in your project's src
folder! This has caused this error many times for me when creating test projects which I copy from existing projects. Hope this saves you time!
Also, creating an XML file with any capital letters will trigger this error.
import com.de.vogella.android.temprature1.R;
i'm new to android development. I had the same problem and revolved around this thread for about a week. It turned out that as you download latest Android SDKs like API 23 which has recently been released, or if you update build tools, you need to modify the build.gradle file under Gradle Scripts if it does not get updated. It is located in app folder of your Project directory. You can open this file with notepad. My file now looks like this.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.example.sukhwinder.justjava"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Make sure compileSdkVersion, buildToolsVersion and targetSdkVersion match the latest version of Android SDK and Build Tools installed on your machine.
Sooo many different possible solutions! For me, I found that Eclipse had created the faulty file in the wrong package. I fixed it by moving it into the same package as the R.java file.
I had the same problem. I fix it by deleting the file in 'gen' directory, then I clean the project then the R.java was automatically generated.
1) see if the xml files in the Package Explorer tree have an error-icon if they do, fix errors and R-class will be generated.
example hint: FILL_PARENT was renamed MATCH_PARENT in API Level 8; so if you're targeting platform 2.1 (api 7), change all occurences back to "fill_parent"
2) if you added "import android.R;" trying to do a quick-fix, remove that line