• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Error, Could not find or load main class

 
Anucool Karvir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per my reference file named book.java should contain a class named book having the static main method.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic