2

I just finished my app, and when I try to save it as an APK, this error appears, all the 'R's in the code turned red. This is not the first time it happens. How do I fix it?

  1. This are all the line with errors in the code, all the R. are in red.:

    setContentView(R.layout.dise);
    final EditText e=(EditText)findViewById(R.id.escribiraqui);
    TextView T=(TextView)findViewById(R.id.traduccion);
    Button TRAD=(Button) findViewById(R.id.traducir);
    getMenuInflater().inflate(R.menu.java, menu);
    if (id == R.id.action_settings) {
    
  2. I tried importing android.R, and now the R isn't red anymore, now the error is after the R.id... or R.layout... or R.menu... All my variables are in red now, with the same error:

    "cannot resolve symbol 'dise'", etc.

3.I just did alt+Enter on the R, then clicked on Create a class 'R'... The error disappeared, is this correct or it could lead to another error?

user3726747
  • 27
  • 1
  • 3
  • What is the error msg EXACTLY? Show us some minimal code that shows your problem. – amit Jun 10 '14 at 17:02
  • 3
    check if you have errors in resource files fix it. Remove `import android.R` and cleand and build your project. – Raghunandan Jun 10 '14 at 17:03
  • I checked all the files, everything is fine, the only problem is in the Main_Activity(Which named just as 'java' is the start while creating the project)... – user3726747 Jun 10 '14 at 17:25

6 Answers6

2

the R gets red when there is a problem generating this file. This can e.g. happen when you have mistakes in your grade-files. I would suggest to open a console in the path of your project and type:

gradle clean build

this should show you the root-cause - and if this works out fine then the red should be gone ( you might have to sync )

ligi
  • 39,001
  • 44
  • 144
  • 244
1

do not fiddle with any code , this "R getting red" issue is very common(and all is to do with gradle), I had it a lot in the past but with new gradle and sdk it is much less nowadays, but for anyone has the same issue do as follow hope it will work for you too,

This worked for me:

  1. Close and reopen project
  2. Press " Sync Project with Gradle file " (is next to AVD manager icon in top menu)

repeat 1-2 if Gradle could not Sync for first time. (mine worked in second time).

source, https://stackoverflow.com/a/31127514/4173238

Community
  • 1
  • 1
bastami82
  • 5,955
  • 7
  • 33
  • 44
0

You can rebuild the project by going to build -> rebuild. If that doesn't work, make sure that the names of all assets are lowercase. That really got me, because it prevents the rebuild.

0

This seems to be a problem for Gradle settings, check your Gradle configuration in the build.gradle file Also make sure to go to

Preferences-> Build,Execution and Deployment -> Gradle -> use gradle default wrapper

Then, Clean and Rebuild your project

Sachith Muhandiram
  • 2,819
  • 10
  • 45
  • 94
0

Just update your Gradle version

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'  
}
JustSomeGuy
  • 3,677
  • 1
  • 23
  • 31
0

Make sure you added the package name in the Android Manifest file

Step 1: <manifest ... package="your.package.name"> ..... ..... ..... </manifest>

Step 2: Make sure you have the same sdk version in [build.gradle::app]

compileSdkVersion 30

buildToolsVersion '30.0.3'