I recently finished a programming assignment using Netbeans and Java. When I run the program in Netbeans everything runs perfect. My issue comes when I try and run it from the terminal. I run javac with all my .java files and it produces a .class file for each one. Then when I try to run the executable it errors out on me.
ls
Board.java KenKenPuzzleSolver.java
Solver.java Cage.java
Size.java Values.java
javac KenKenPuzzleSolver.java Board.java Cage.java Size.java Solver.java Values.java
ls
Board.class Size.class
Board.java Size.java
Cage.class Solver.class
Cage.java Solver.java
KenKenPuzzleSolver.class Values.class
KenKenPuzzleSolver.java Values.java
java KenKenPuzzleSolver
Exception in thread "main" java.lang.NoClassDefFoundError: KenKenPuzzleSolver (wrong name: kenkenpuzzlesolver/KenKenPuzzleSolver)
Also, when the program is run from the terminal it should take in an input file and the name of an output file ie "java KenKenPuzzleSolver input.txt output.txt", and I am not quite sure how to do this.
Why don't you generate an executable with netbeans? You don't have to compile your code every time.
input.txt
and output.txt
are called arguments. They will be stored in the String[] args
array in you main
function.
You did not provide the classpath parameter.
Use javac -cp YOURCLASSPATH KenKenPuzzleSolver
The class that you are running should be public and should have the class name same as your file name. It seems like your file name is "KenKenPuzzleSolver" but your class name seems to be "KenkenPuzzleSolver" ( Observe the lowercase ken ). correct that and recompile and re run.
您一定已经搞砸了案例,因为错误已经很明显了,而不是在KenKenPuzzleSolver
类命名为kenkenpuzzlesolver
,而不是KenKenPuzzleSolver.java
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.