I'm using netbeans and get the following output:
Caused by: java.lang.ClassNotFoundException: battleships.BattleShips
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: battleships.BattleShips. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
My main class is named after the file i'm using, i've cut and pasted from source code into NetBeans
If I click on properties > run for the project it can't find the main class. Furthermore the class dir of the project is empty.
Rob Brew wrote:I refactored (changed) the class name to battleships to see if that would make a difference, still no joy.
Just to clarify, your own post from 18:20 indicates the class name is battleships (all lowercase). That might be the problem.
Anyway, you can try to verify the project settings: right-click the project in the Projects windows and choose Properties. Select the Run category in the leftmost pane. What do you see in the Main Class textfield? Can you click the associated Browse button and select the correct main class?
Rob Brew wrote:I've tried the properties > run and selected the path but no main class can be found.
Do you refer to the runtime exception, or to the Properties form? In other words, can you select the battleships class in the Main class field of the Properties form? (If not, that is certainly part of the problem.)
What package is your class in? Does the directory structure of your project reflect the package declarations in your class(es)?
Each file is in the battlehsips package.
The runtime classpath of the main class battlehsips is set correctly. I can't set battleships as the main class in the properties form, even with the directory typed in.
Using java on the command line fails with the package declaration at the start of each file. Without this java from the comman line can run the program. I know i need to set the run paramater on the properties box, but what to?
Do you have your source file (battleships.java) located in the src/battleships directory? This is the default organization of Netbeans projects; Netbeans could have problems locating your classes if this is not the case.
What OS do you use (Windows or Unix)? Under most circumstances, Unix, unlike Windows, is sensitive to case in file/directory names.
Rob Brew wrote:Using java on the command line fails with the package declaration at the start of each file. Without this java from the comman line can run the program.
Do you mean that if you remove the package declaration from source files, you can run the application from command line (using java), but if you keep the package declaration, it does not work? In this case, I think the classpath parameter should help.
I'd advice to recreate the project anew from start, so that NetBeans creates the directory structure as it likes (make sure to create packages and classes by using NetBeans' commands and keep package declarations there), and copy at least parts of the sources there via clipboard. If it works this way, you can then compare the created files and directories and possibly spot the difference.