reset password
Author Message
gjackso2
Posts: 24
Posted 18:35 Oct 11, 2015 |

Hey all, I have most of the program working fine, but am having trouble getting it to run from the command line. I navigate to the directory where the "CS451_Jackson.class" (in "workspace/projectname/bin/packagname/"), and then type "java CS451_Jackson..." but get the error:

"Error: Could not find or load main class CS451_Jackson"

I do the exact same steps with other programs (from last quarter, say), and it works just fine.

Any advice?

Thanks!

vsluong4
Posts: 87
Posted 18:41 Oct 11, 2015 |

Did you compile it first?

 

Type >javac CS451_Jackson.java

to run the java compiler and compile it into the same folder

Last edited by vsluong4 at 18:41 Oct 11, 2015.
gjackso2
Posts: 24
Posted 19:00 Oct 11, 2015 |

I have compiled it, but through Eclipse. When I attempted to compile using javac on the command line, I get an error that javac is not a recognized command. I did some checking, and it turns out my Eclipse path is pointing to the Java JRE and not JDK. I'll try installing JDK and updating the environment variables.

vsluong4
Posts: 87
Posted 19:15 Oct 11, 2015 |

Eclipse compiles it into a different folder from the source folder

You are trying to run the compiled file while inside the source folder, but it doesn't exist there

Looks like you haven't set your java path yet

try >set path=%path%;C:\Program Files (x86)\Java\jdk1.8.0_60\bin

>javac CS451_Jackson.java

gjackso2
Posts: 24
Posted 19:35 Oct 11, 2015 |

Downloaded the SDK and updated environment variables. I can get "javac" to run, and it compiles the program. Then I recheck the directory listing and see that my "CS451_Jackson.class" file is indeed present. Then I run "java CS451_Jackson" and get the same error, "Could not find or load main class CS451_Jackson". Even though I'm looking *right* at it.

Same thing happens when I move to the "bin" directory (where Eclipse saves .class files).

Thanks for the posts so far. I'm still confused, but undaunted...

Last edited by gjackso2 at 19:37 Oct 11, 2015.
vsluong4
Posts: 87
Posted 19:40 Oct 11, 2015 |

Try this tutorial and see if you can get a simple program to run http://www.skylit.com/javamethods/faqs/javaindos.html

gjackso2
Posts: 24
Posted 20:07 Oct 11, 2015 |

Followed the tutorial and all worked fine.

Error persists when trying to run my program.

vsluong4
Posts: 87
Posted 20:31 Oct 11, 2015 |

Then either you don't have a main method or your CS451_Jackson class is part of a package are my guesses

gjackso2
Posts: 24
Posted 20:47 Oct 11, 2015 |

Thanks for your suggestions. I do have a main method (I'm able to run the program from within Eclipse), and I tried moving my code out of the package "basic" and into the default package, but the results are the same.

Is no one else having this issue?

vsluong4
Posts: 87
Posted 21:01 Oct 11, 2015 |

http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean