R.java problems with generating - android

I tryed to create new project and in my R.java there was next code, for example:
public static final class layout {
public static int activity_main=0x7f030000;
instead of
public static final class layout {
public static final int activity_main=0x7f030000;
So I can't build project normally, because it generates public static int without final.
What should I do?

Right Click on project --> Android Tools -->fix project properties
before doing this remove import statement like
import android.R.*..
or try clean project from
project --> clean

This could be because of many things.
1. Check your xml files have no errors in them as this can stop R.Java from being automatically generated.
2. Clean your project. This will rebuild your project.
3. Delete any android.R import statements.
4. Close and re-open eclipse.
I also wouldn't recommended fiddling with the R.Java file dirctley.

Related

Why does my BuildConfig class keeps getting duplicated every time I run my project

I migrated my project to Androidx and every time I run my project I keep getting this error that says class BuildConfig is public, should be declared in a file named BuildConfig.java. I know that the cause of my is that every time I build my project my java BuildConfig class keeps getting duplicated. Which gives it a name such as BuildConfig1, BuildConfig2 etc.. I constantly have to keep deleting it and rerunning my project in order to compile this is really annoying does anyone know the cause of this and perhaps a fix? This is my BuildConfig class
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.examp.smartshop";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}
Try to clean project(Build->Clean Project) and rebuild Project(Build->Rebuild Project).
or
Try deleting .gradle folder , build folders, .iml file.( You can do thing by going to Project window and choose 'project' option. And do the rebuild project again.
or
last resort File->Invalidate Cashes/Restart.
Vote If it works.
Happy coding.
Thanks.
Under the project search for a folder named ".gradle" and while at it search for another under the 'app' folder named "build". Delete the two folders and run your app. It will solve the issue. See this
The error arises as a result of duplication of files hence Android Studio is unable to determine which files to use.
I had this same issue after doing some package restructuring.
I tried deleting the build and .gradle directories and restarting Android Studio with invalidating caches with no luck.
After the package restructuring, not only did my androidTest files end up in my main directory, eventually I noticed I had ended up with a BuildConfig.java in my source directory. I really should have been more careful with the refactoring preview.
Deleting the BuildConfig.java from my main/java/package directory resolved this issue for me.

destroyed gradle file(Module:PackageName) And Not Sync Project

I opened my project today and came across this problem:
The gradle (Module: app) file is healthy, but the other gradle file associated with the project is cluttered and corrupted.
The Codes of gradle File(Project: PackageName) is shown below:
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* gradle plugin from the resource data it found. It
* should not be modified by hand.
*/
package android.support.v7.appcompat;
public final class R {
private R() {}
public static final class anim {
private anim() {}
public static final int abc_fade_in = 0x7f010000;
public static final int abc_fade_out = 0x7f010001;
public static final int abc_grow_fade_in_from_bottom = 0x7f010002;
public static fi
This problem does not allow me to continue my work and stop me. Please help me faster. Thank you
You should always use a versioning tools (git, mercury, svn, etc.), even if it is a practice/test project of yours, so that you can recover from these errors
Any case, you can still use Local History to recover this file if you are using Android Studio: https://stackoverflow.com/a/25076685/783707 . Simply go to Project structure, right click your file, click on Local History, and choose an older version of the file to go back to.

Error in R file after using "=" as an id for a TextView

When I was working on my layout file, I named by accident a TextView with '='.
I renamed the widget with another valid id but after a build, I have an error in my R.java file :
public static final class id {
public static final int ==0x7f0b0086;
Thank you for your help.
Try Clean and Rebuild your project.
or
Close your project and restart android studio.
or
if problem not solved then on the main menu select File > Invalidate Caches/Restart

Trying to use code from another project by including it in my build path

I'm trying to figure out a way to share code across projets. this is what i did
created a project called sharecode and made the following class
package codelib.com;
public class cShape {
}
made a android project called testsharecode
whent to properties->java build path and clicked on projects at the top.
clicked add, and added sharecode
created a class to try include the cShape class from the sharecode project
package com.example.testsharecode;
import codelib.com
public class parent {
cShape test;
}
On my import i get a error saying
"only a type can be imported, cadelib resolves to a package"
on cShape i get a error saying the def does not exist.
How can project testsharecode use the code in projetc sharecode?
have you tried the following method :
right click on the distination projet, Build Path -> configure build path
chose project then select testsharecode
back in your distiation project now you should be able to use your public classes.
hope this helps

Layout can't be found

When I use the following line :
LinearLayout layoutRoot = (LinearLayout) findViewById (R.id.layoutRoot);
it gives an error saying that R.id.layoutRoot cannot be resolved.
what does it mean?
Verify that in your imports, you have something like:
import com.myproject.R
and not
import android.R
Check your R.java file (which is in the gen directory) and you will see that the layouts identifiants don't belong to the id class but the layout class.
public static final class id {
}
public static final class layout {
// Layouts are here...
}
So it should be: R.layout.layoutRoot.
Save the project
Exclude bin, gen from svn (if you use it)
Commit, update (if you use svn)
Clean
try to build again. If won't work:
Delete gen, bin
Save
Build.

Categories

Resources