0

I'm trying to run a simple genetic algorithm example from here and I compiled the given code example at the bottom of the page. I've compiled the code two ways, made a Java Application but with classes only and ran it in netbeans and I can run GA.class on netbeans fine. Then I retyped it in gedit and saved all the files. First it was a problem trying to compile the files as all of them had dependencies to each other but I solved that with setting the classpath from a few posts here.

My current problem is that it gives me the Could not find or load main class GA error. I've copied the code word by word. And from a few of the posts, most mention about setting the classpath and I already did that with this:

export CLASSPATH=/home/Desktop/Genetic\ Algorithm which is where I put Population, Inididual, Algorithm, FitnessCalc, and GA.

and I tried to run it with multiple lines, here are a few:

java simpleGa.GA

java -cp /home/Desktop/Genetic\ Algorithm/simpleGa GA

and some iterations where I simply changed GA to simpleGa.GA etc. Did I set the classpath incorrectly, or is there something wrong with the code that makes it not possible this way, or might I need some other tool for this, which I don't think anything else is needed(?)

PS: not sure if this question fits here but I just started learning genetic algorithm, do you have any references you would recommend to read in order to understand better or delve deeper into how it works etc

nisyedlah
  • 103
  • 1
  • 14
  • Need to see the path to the `.class` files from where you attempt to run the code. "CLASSPATH" doesn't work the same as "PATH", it won't find files until the JVM finds the main class. – markspace May 23 '17 at 03:45
  • @markspace the classes are all in the same folder, the classpath that I set. Or is that different as well? In any case the .java files and the classes are in the same folder – nisyedlah May 23 '17 at 04:55
  • That may be the problem then. To find the the class `simpleGa.GA`, the `java` command will look for "simpleGa\GA" on the file system. Your path has to match your package, relative to where the classpath is set (or where you first run a file if it's just a .class file). – markspace May 23 '17 at 18:14
  • [This related question](https://stackoverflow.com/a/44098455/819340) might help you... – Paulo Mattos May 23 '17 at 21:25

0 Answers0