Using eclipse to create a new project - java

I tried to create a new project "hbv8" by going to file -->new java project, and I used the default settings.
Why is my hbv8 has an red x at the corner of its icon? It also automatically imported the source code from hbv7 with me importing it. Can someone please help? Many thanks in advance!
The problems window shown as below, but I didn't import those things from hbv 7 so I can't figure out what was the problem..

Your source files are in folder hbv8/src/src/hucklebuckle - note the two /src folders.
Eclipse expects the files to be in hbv8/src/hucklebuckle (just one /src)
So move the files or recreate the project.

Related

Eclipse not recognizing class after import of jar file

I have tried creating new projects. Removing and adding the jar file. Nothing is getting this thing to recognize it. I don't know if I am adding this correctly or not. Could someone please direct me, thanks.
EDIT: After some research using the help from the comments, it seems the problem is that the jar file only works if I am using a default package. I obviously don't want to use the default package so how can I change the Jar to fix this?
I don't know if this is a workaround or fix. I had to exclude the folders from my build path to use the jar file that had a default package. I did figure out how to deconstruct/reconstruct but for future reasons, I would not want to do this everytime someone hands me a file using the default pkg. So here is a screenshot of a working setup:
Please click it if it is not big enough for you. The summ/wint folders are excluded and I am able to use a class from the jar file without editing the jar file.
Money dd = new Dollar();
Thanks for all the comments.

In Java where do I put my sprite files to make this open source code work?

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.

Eclipse error with archived java projects "editor does not contain main type" [duplicate]

This question already has answers here:
Error: Selection does not contain a main type
(24 answers)
Closed 8 years ago.
I am receiving the errors: Editor does not contain main type, or, Selection does not contain main type when I import an archived Java project into Eclipse and try to run it. I have gotten this error on several different operating systems.
Archive Protocol
Export project
General->Archive File
All are selected: project folder, .classpath and .project
[x] save in zip format
[x] create directory structure for files
[x] compress contents of file
A Work Around That May Explain It... but how?!
I notice that when I import an archived project into an existing project (a blank Java project), The folder hierarchy is something like:
Project
src
bin
imported_project
bin
src
actual_code.java
Now, when I try to run actual_code.java, I get the above error. I discovered the following work around: if I drag actual_code.java and drop it into Project->src and then run it, it works.
This is a nice work around. However, I would prefer to be able to run the imported project without moving things around. Any suggestions on how to do this? It seems like it should be a trivial fix--it simply seems like the project isn't importing to where it ought to.
And yes...
I have tried every method I have come across to remedy this. That includes quite a few from this site and others: syntax, libraries, source path, restart eclipse, rearchive, different operating systems, different machines... etc.
The .java files are in the src folder before I archive them, and my build path seems correct.
You could import the archive as a Project instead of as files into a newly created blank project. Use Import > Existing Projects into Workspace. Then, use Select archive file.
You might want to put the src folder of your imported_project in classpath.
Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder
I also faced the same error ajnd after reading above article i just drag/drop my class-file to src and new class-file generated in src is working fine .
I had the same problem after I New/Java Project then pulling src, docs, lib, examples, ... folders. I could not import it as an Eclipse project since the code is not an Eclipse project. The main is right there in the example code, but the IDE would find it.
The solution for me is deleting the project from the IDE, then recreating it with the Eclipse IDE. When recreating, the IDE cached all the sub-folders for me. Also, make sure you add the code onto the Java Build Path as Source using the 'Configure Build Path...' of the project.
Restarting IDE, closing then reopening the file didn't help me.

Eclipse: don't notice Error when import fail Class

This below image is my eclipse of my two different projects. And each black rectangle is a package in folder src of Eclipse project. As you know, there a different point: The icon of each package is different.
1) first project: package has normal icon. (like java package)
2) second project: OPPS !!! It displays a folder.
And, the problem that I want to tell is: in project 1, when I type something wrong, eclipse has notice errors. For example: I declare: Example() example = new Example();
But at project 2, Eclipse cannot. That you have seen on my screen: Eclipse eclipse = new Eclipse();
Obvious, when compiled, It failed.
I think that I might do something wrong, and I just a newcomer to Eclipse, and really don't understand much this IDE.
Please help me for my problem.
thanks so much :)
As I think, because you have imported "your package" just by move your source. there are two ways (with my knowledge) that might work:
1) Like Baldrick does.
2) go to Properties\Java Build Path\Projects: add a project that contain package you want to add. this will make two project a linker. when you compile this project, this will also compile project that you link to.
Right now the second (lower) project doesn't have the source directory set up as a source directory, so it isn't trying to compile it. No compilation, no errors. Update your project settings by right-clicking and adding the source directory to the source paths.
Right click on your projects, go to "Properties" and "Java Build Path". In the "source" tab, add your folder src to the list of source folders.
Looks like you've created a New Folder in your project AndroidGame whereas you created New Package in your other project (can't see name).
You should create a new package in your AndroidGame source folder and "Refactor->Move" your source to it.
As an Eclipse newbie question, you should always Create Package (File -> New -> Package) when creating a package. Folders tend to be required for web content, images, resources (say for property files to be added in your target classpath), etc.

Eclipse IDE project directory structure help [Java]

I have been learning Java and have had no problem with projects in which multiple .java files were in the same Default Package.
I am now trying to separate code and create folders for images, but everything I have tried has failed.
How do I properly add folders for images and other classes, and properly set the path to it?
All paths should be relative to the project, I know that much ;_;
Here's a link to a picture of my IDE and error message from program output:
http://img262.imageshack.us/img262/8415/directory.png
Thanks!!
First off, your Java code itself should go into a package, not the default package. Next, you may be able to refer to the image file by prepending src/ to your path:
"src/Textures/Crate.png"
But better would be to get the image as a resource, not as a file using the Class#getResourceAsStream.
Drag using the mouse your Textures folder to the LWJGL 6 project folder.
Try giving src/Textures/Crate.png as the path to the FileInputStream constructor.

Categories