aspose file tools*
The moose likes Java in General and the fly likes Java Error, Could not find or load main class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Error, Could not find or load main class" Watch "Java Error, Could not find or load main class" New topic
Author

Java Error, Could not find or load main class

Anucool Karvir
Greenhorn

Joined: Nov 08, 2012
Posts: 3
Hello I am new to java, jumping in from C#.

I tried compiling a hello world. and that works fine.

But i then tried a object array program.(unfortunately i dont have a access to code right now. and i am doing this in a hurry)

code structure is like
filename books.java



when i compile. it compiles with no errors. and i get two class files. books.class and booktest.class

when i try to run C:\java books

it gives me the could not find or load main class error.

why is that?

Classpath variable is set. i am in the directory where all the files are. I am making sm small mistake but i could not get where.

I will update the code asap.
subhod lagade
Greenhorn

Joined: Feb 17, 2009
Posts: 6

as per my reference file named book.java should contain a class named book having the static main method.


Java Professional
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39814
    
  28
More likely you should be writing
java booktest

By the way, the naming of those files is inappropriate; class names should start with Capital Letters.
Anucool Karvir
Greenhorn

Joined: Nov 08, 2012
Posts: 3
I tried using both, books and booktest.
And yes i know naming is wrong. I have done it right in my code. I typed my first post from a tiny net book. I could not operate the keys efficiently in that cramped keyboard. (Typing this from an iPad )

Point is

Java books gives me error: Main method not found in class books

Java booktest gives me error: could not find or load main class Booktest
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Anucool Karvir wrote:I tried using both, books and booktest.
And yes i know naming is wrong. I have done it right in my code. I typed my first post from a tiny net book. I could not operate the keys efficiently in that cramped keyboard. (Typing this from an iPad )

Point is

Java books gives me error: Main method not found in class books

Java booktest gives me error: could not find or load main class Booktest

It's difficult to be certain without seeing your exact code and command line but the error message suggest that you are actually typing
java Booktest
Java is case sensitive so unless your class is actually called Booktest (and not booktest or BookTest or anything else) you will get this error.

Note that this is not the only possible reason for this error but with the limited information you're supplying it's not possible to be more definite.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39814
    
  28
Just as well I never bought a netbook, then. I have an 11″ screen on a small laptop, but at least I have full‑size keys. And I have 1368px screen width.
We can only guess about the cause if the code you post is not exactly the code you are using.
Anucool Karvir
Greenhorn

Joined: Nov 08, 2012
Posts: 3
Here is the code.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

So now the class is called "Bookstest" instead of "booktest"?

Note that spelling and also case is important for Java. If the class is called Bookstest (with a capital B and an s), then that's what you have to call it. Not "bookstest" or "booktest", but "Bookstest".


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Error, Could not find or load main class