Larry Evers wrote:Tryed setting up the new project "from existing sources" in the IDE, using the Mines.java and Board.java files held in a C:\JavaProject\Mines\MinesSource folder.
This loaded both sources into the IDE Project section.
However, the first line of each source is underlined in red giving an "incorrect package" error. Any ideas on why that is?
Just check that both the classes are in the package, they are supposed to be!!
Plus, I would suggest you to write your own code, rather than getting a code from internet, and running it.. This will help you understand better..
And start with notepad and Command Line.. Don't directly get to an IDE.. This I am saying assuming that you are a beginner in Java..
You will understand whole point of packages and other stuffs better..
Joined: Aug 07, 2012
Thanks for the reply. Speaking as a VB programmer, the Java code itself is not too bad from what I can tell so far, but the IDE/compiler are taking some getting used to. I managed to get the Snakes game at that url running ok. The Minesweeper game will have to wait as I have to manufacture its icons. I'm looking at these practical examples as I can rewrite and modify them to get a better feel for the code, as well as trying to get a handle on the IDE/compiler. Unfortunately the IDE tutorials I've seen are very generic. Will note my progress with the games mentioned here shortly. I'm really only at my fourth Java program, so things aren't going too bad.
Joined: Aug 07, 2012
Wasn't used to using multiple source .java files, but I got the Snake and Breakout games to work by using the following:
Start a new project, java with existing sources.
Project name: Snake
Project folder: C:\JavaProject\Snake
Buildscript name: build.xml
checkmark "set as main project"
Source package folders: C:\JavaProject\Snake\SnakeSources
in that last directory I had:
The IDE says: Project Snake does not have a main class set, select the main class: Snake
In the IDE Project window, the Snake.java and Board.java both show errors if the first line of each: "package snake;" is left in. If taken out, the source builds and runs ok.
Note I used freeware icons in .png format, edited by Real World Icon Editor found on the web.
So, I now can edit and run Java programs that have multiple src files.
However, I still am having a problem with setting up the package name in the IDE when I start a new project. I can only get the project to run if I use the default package, not the "package Snake;" specified in the source code files.
NetBeans should have placed a red underling under the "package snake;" line in the source file. If you hit ALT-ENTER, it would have provided tow options to fix this error, one of which is "Move class to the correct folder". That will do the work of creating the "snake" folder and moving the .java files there.
Thanks Peter, your correct. I saved the sources and .png files, then deleted the project. Started again with the files in the new directory structure, and the IDE no longer showed a red line under "package snake;" as it has before. The project built and ran ok. Still going through "Java: The Complete Reference", with a couple of other Java books after that.