II updated AS to the latest stable build and all of my projects melted down. Only Java files in the main directory (com.company.app) can find R.java as intended. ALL of my subdirs can't find it. I did not have to import R.java before the update. I rebuilt my projects from scratch, restored backups, copy-paste to new projects from the backups, reinstalled AS, restarted PC, invalidated caches and restart, cleaned, literally every go to insta-fix-it solution that the internet always recommends and still I can't get this to work.
Can someone tell me how my subdirectories cant find R.java but other files in my main directory can? Is this a feature change in AS or something? Are we now supposed to import R.java? There are no XML errors. My project built before I moved any subdirectory files back to my main package. The package name exactly matches the one in my manifest.
Edit 1: I can rebuild my project and make R.java. The main package files still see it without the import, but the subdirs can't find it.
Edit 2: I can move a file from my main package to a subdir and it still finds R.java. This appears to be a compiler glitch.
Edit 3: Importing R.java makes the errors go away so I guess that is a solution. I am leaving the question open because this makes no logical sense.
You need to understand how App resources work.
When you build your android project, all of your resources in /res folder will be mapped automatically in generated your.package.names.R class.
Now you want to access the resources through the class. It's only make sense when you need to import the file when you use it in different package.
I had this issue, even though the error wasn't being underlined in red there was an error in my strings.xml. Go to Values->strings.xml and check if you duplicated any strings.
Related
I am creating an external library to share code between my client/server programs. IntelliJ can't seem to import this jar file and I can't understand why, I followed all the advice I've found online.
I added the jar to my lib folder and added it as a library in my main module (it's called 'common':
This is the error (repeated on each instance of me using User or Packet). On import statements it says "package common does not exist":
I've tried invalidating caches and that didn't seem to work either. I tried this same import on a new project just to see if I was doing anything wrong and it worked perfectly on that new project so I'm not sure what's going wrong here.
EDIT:
I've noticed that this error only happens in files that are in packages within the src folder. So basically, Main can find the jar because it is only in the src folder, but RegistrationController can't because it's in src/communication.
The problem was that the shared code I was making was not in a package, just a src folder. Because of that, the code that was in my default package (src) could access the classes, but not the code in packages. To fix this, I put the shared classes in a package (com), exported them as a jar, and imported that into my project. Now, my packages can do com.Packet or com.User and get the files successfully.
So, I deleted a couple of .java files from within eclipse because I didn't need them anymore. However for some reason another class still uses them and compiles without a problem. When I go to the declaration of the constructor of one of the deleted classes a .class file opens of that class even though I thought they got deleted by eclipse when I deleted their .java files.
I have tried to clean the project and I tried to find the .class file using the system file explorer in the folders that are listed in
project > properties > resource > linked resources. However I couldn't find them.
Now, since I deleted those files/classes there should be a compile time error wherever they are used but everything compiles without an error, even using the code that should've gotten deleted. A colleague that recently joined the project does receive compile time errors, since he doesn't have those class files. And I want to get them too, so I can fix the code where the classes were used. Of course he could show me the lines of code that are affected but if this happens again he would probably be affected as well as he would have the class files by then.
Try doing the following
Go to project > properties > Java Build path >Source
under that you can find Default Output Folder section, simply delete the classes folder under that location with in your project.
Try cleaning the project.
Or
Simply close the eclipse and reopen it again, sometime this would work for me.
Hope it resolves your problem
If you just deleted the sources, they binaries would still be there. So open the Navigator View and go to the project in question. Look for the bin directory and delete the appropriate class files. Otherwise, delete the project itself.
You should also ensure that no other programs depend on those class files.
I found the problem. Someone built a .jar file I didn't know of which contained a lot of old code.
I found it by right clicking the constructor and selecting
references>project
My R.java gives an error
public static final int 1405308882_more = 0x7f020000
Don't know or understand why its giving this error, i regenerate the R.java file and it still gives me the following above. and when i hover my mouse over it, it says
underscore have to be located within digits
I tried editing it but when it compiles it still regenerate the same name variable.
Please before anyone starts rating this question as usless take your time to understand it
I don't have error in any of my java files either in the src folder or layout folder every thing else is fine its just the R.java that generates that constant so please understand before you jump to conclusions. Thank you.
There might be some thing error in your res folder once check each and every file and clean your project once and refresh it again..
Sounds like the R.java file has not updated, try some of these general pointers to begin with:
Do not manually edit any of the files in the gen folder, as these are automatically built for you.
If you find it is out of sync then try refreshing the project.
If that did not work try a clean (project -> clean)
If that did not work delete the gen folder, from within Eclipse, (do not panic) it will then be rebuilt by Eclipse - however if there is a coding error of some sort it may not do this straight away.
Hope this helps..
It wasn't the XML file that was the issue. It was an image in the resource folder with a name that didn't follow the standard naming rules and thus made the R.java to generate that error.
The reason it regenerates same is because it regenerates from your code you should check the .xml files of this project the problem is probably at 1 of them try clearing xmls you have created then regenerate it.
I have a massive problem, and I can't find a single thread out there that specifies this problem.
I'd been watching Google IO, and the Android Studio was mentioned, I downloaded it, installed it, and opened my project into there, as I wanted to try out some of the new features, Fine and dandy, (on a separate note, I love Android Studio)
It was working before in Eclipse, and I literally changed nothing about my project, I was only looking around at the device preview features and stuff, didn't touch any piece of code what so ever, just having a look at some of the features..
Went back to eclipse, and my generated folder only showed R in, no tree structure of R or anything, just R.java, and R inside it, and everything in my classes were underlined, but it wasn't the R that was, it was the value after it (ie. Cannot find R.layout.main) which I thought was really weird, so I cleaned my project, and it disappeared, I now have a project without a generated R.java file.
To note; I changed nothing about my project, all my XML files were absolutely fine, i've tried every trick I can find on StackOverFlow and other websites (removing some of the XML's, painstakingly going over my 15 layout files character by character for an hour, removing imports, build paths, etc) and nothing works, and i've been trying to do this for almost 3 hours now.. Does anyone have any experience doing this, or any solution?
in the Gen section of your project, try to delete the R.java
It should re-generate, I had some issues like that in the past..
Give it go.
The R file may not be generated due to errors in the project.
Check your xml files in res folder. Also read Error log of the eclipse.
(Windows -> Show View -> Problems)
The best way is copy R.java from another project and Past it in gen
And then Delete R.java file then the system will recreate R.java back for you..........
I've been trying to import a project that works on a friend's computer, however no matter what I try, the package hierarchy is completely lost and the result is this
Has anyone seen this issue before? I've been struggling with it for a while. Occasionally creating a new project and copying in the src folder works, but I've been unsuccesfful in my recent attempts.
The presentation of packages is a user option. Click the little down-arrow at the top of the package panel, then select "Package Presentation" from flat to hierarchical.
Turns out we weren't including the .classpath file in the source control. Facepalm. Good answers, though.
It could also be that the folders are not listed in the project as Source Folders. Go to the project properties and check that the root folders (looks like "data" and "src" here) are listed as source folders in the Build Path.