Before posting this message I read tens of threads but with no success. I am trying to import a package into one of my JSP files and I keep getting the same error:
The import cannot be resolved.
I believe that something is not right with my project structure. I have tried everything, from cleanup, rebuild, even creating another project from scratch.
This is the structure of my project:
And these are the contents of my build path:
I would greatly appreciate any kind of help, this is a big blocker right now for me.
Yes, it's your project structure. Your source files are not actually under the src folder that would be listed on the Source tab of the Java Build Path property page you're showing (you can see how it's laid out that folder's contents to resemble package names). Either move the files to where they're expected or update the Source tab to point to where you're actually keeping them.
add the Java Resources/src folder to the build path or the library build path.
Thanks a lot for your answers, I have changed the project structure like in the image below and now it works:
Related
I am a beginner and I am trying to learn by messing around with some open source game code.
I was setting it all up in Eclipse but I don't know where to put these sprite gif files.
In the code I found this:
URL url = this.getClass().getClassLoader().getResource(ref);
And when I put all the class files under a java project together and tried to run I got this error message:
Can't find ref: sprites/ship.gif
Of course the code came with sprites including ship.gif. I just don't know where to put it. I tried making a folder under the java project called sprites and putting it in there.
I don't have a res folder.
The this.getClass().getClassLoader().getResource method look for relative path of the data from the package of the class.
Assuming your class is com.my.package.MyClass, you usually have your project organized containing at least in your case:
com/my/package/MyClass.java
com/my/package/sprites/ship.gif
Most of the time, you certainly have a resources or a images folder for your java project.
You can only load those resources if they are on the classpath. Try to add the sprites folder as a source folder on your Eclipse build path and try again.
Put the .gif in the jar.
This can be achieved by creating dedicated folder you add in the sources of eclipse. Often this folder is called "resources".
Be ware that in some cases a "/" is required at the begining of ref.
Thanks everyone.
How I fixed my problem:
When I downloaded the source I opened folders and went to the class files and copied them to my project and then I was trying to do the same thing with the sprites. What I didn't realize is that if I just drop the two main folders "org" and "sprites" into the source file of my project then it all works on its own. These two folders were the first things I had after downloading this open source code.
I am attempting to edit code from an old developer.
I know it is bad practice but what she said I had to do was create a dummy project and then copy paste the packages in question modify what I need to modify then compile and copy the classes that I changed into the directory where the classes in use are stored.
So I created the dummy project and copied the packages/files into the source folder of the dummy project but I keep getting a "package org.jdom does not exist" error.
The error appears on the lines:
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
When I copied the folders/files into the source folder I copied the entire "org" directory.
You can see from my screenshot that the package is in the Project Explorer
I have several things to resolve the issue but none seemed to work.
I tried adding the "org" directory into the classpath environment variables.
I tried adding the "org" directory as a library to the project.
I have tried clearing the NetBeans cache after doing both of these but none of these 3 things worked.
Below is a screenshot of the projects src folder in file explorer
Can someone explain to me what I need to do to get this issue resolved?
I was adding the wrong files to the libraries section of my project.
I was adding the source for jdom when i should have been adding the jdom .jar file.
Thanks for the help guys.
install jdom at your library folder, there is a new version of jdom try to download it and install it in your project directory.
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.
I know this is a well-known problem
but I did every possible thing:
cleaned the project
re-build
remove the project and add again.
but still.
the R file does not updated
what do you suggest me to do?
thanks
socksocket
Make sure that you have chosen the appropriate target build settings from the project properties
Cross-check the platform versions with the layouts you have used in your app
Remove import statements such as import android.R.*;
OK. found the solution
I had sub-directory inside "raw" directory and I think it is forbidden for some reason
I moved the mp3 files to "raw" dir and removed the sub-dir called "sounds"
and now it works!
cheers!
I'm working with some people on a java project. Problem is, I'm the only one using eclipse. The source files are located in svn in trunk/src/*.java. However, if I import that as a project directory, the default package is "" instead of what the actual project package name is.
Is there a way to change that without changing the source location and the package name?
Thanks!
If you mean that you want code in package foo.bar without having a matching directory folder of foo/bar under some source root - no, I don't think Eclipse supports that. While the convention of source locations having to match package structure isn't enforced by the language specification, it's mentioned there and so widely respected that I think it would be a bad idea to do anything else.
Eclipse requires a directory structure that matches the package structure. There is no option to have some package prefix that isn't reflected in directories.
IntelliJ can work with this, and it's what most people expect to see most of the time anway.
I think you are checking out the incorrect root folder.
If you are trying to work with a collection of source files located under trunk/src/ you may be don't need to check out this folder, because you will loose your reference to the main package (for example foo.bar) because it will be the base package.
You may need to check out the trunk/ folder, because Eclipse expects to find the source files under the default /src folder. Once you have your main root folder (with a lot of files like .project, .classpath inside), it is likely possible that Eclipse will recognize your folder structure and configuration and your project will compile without problems.