“R cannot be resolved to a variable”? [duplicate]

2018-12-31 05:48发布

This question already has an answer here:

In Eclipse, I've created a project from a source and now it shows errors - "R cannot be resolved to a variable". From what I found here, I had cleared and rebuilt the project, but still the R file doesn't appear in the /gen folder.

Any ideas?

30条回答
何处买醉
2楼-- · 2018-12-31 06:49

If Clean/Rebuild Project doesn't work try to check our package name in AndroidManifest.xml.

The problem "R cannot be resolved" happens when you change your package name in the AndroidManifest.xml file. It uses your Android package name to create a subdirectory under the "gen" directory where it stores the R.java file.

查看更多
低头抚发
3楼-- · 2018-12-31 06:49

It is possible you have an error in your *.xml files: layouts and etc.

查看更多
骚的不知所云
4楼-- · 2018-12-31 06:51

Did you just update both sdk and adt(from 21 to 22), then you need to install a new item: Android SDK Build-tools

Refer to: Eclipse giving error, missing R.java file after recent update

查看更多
时光乱了年华
5楼-- · 2018-12-31 06:51

your android manifest must start with correct package

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="HERE - Correct package NAME"
    android:versionCode="1"
    android:versionName="1.0" >`
查看更多
时光乱了年华
6楼-- · 2018-12-31 06:51

I solved the problem with resolving R resource on fc19.x86_64 and ADT v22.0.5-757759 by installing additional libraries after Fedora and ADT upgrade.

yum install ld-linux.so.2
yum install libstdc++.so.6
yum install libz.so.1

Those libraries are required by adb (Android Debug Bridge version 1.0.31).

Then restart Eclipse and perform project clean Project->Clean check project you would like to clean.

Hope it helps :)

查看更多
人间绝色
7楼-- · 2018-12-31 06:51

Problem was eclipse was not generating R.java. To resolve this issue please go to project->clean... and select your project and select ok and then clean and build project and import your package name R file(Ex com.demo.R). It works.

查看更多
登录 后发表回答