aspose file tools*
The moose likes Beginning Java and the fly likes Sams Java in 21 Days java.lang.NoClassDefFoundError: main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sams Java in 21 Days java.lang.NoClassDefFoundError: main" Watch "Sams Java in 21 Days java.lang.NoClassDefFoundError: main" New topic
Author

Sams Java in 21 Days java.lang.NoClassDefFoundError: main

Patches O'Connell
Greenhorn

Joined: Oct 27, 2011
Posts: 5




With the above code, I get the error:


I thought maybe it was the way eclipse was using my file structure as a package, so I eliminated that by removing the custom package line and compiling and running them on my desktop. They compile into classes fine, it's just when actually trying
to run them, it won't work. I'm stumped, the book doesn't give me an answer, and I can't really progress further without fixing this or at least knowing why it's happening so it doesn't happen again in the future.

Any help would be most appreciated.

-P
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Java is case sensitive. The method should be called main, not Main.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Patches O'Connell
Greenhorn

Joined: Oct 27, 2011
Posts: 5
Rob Spoor wrote:Java is case sensitive. The method should be called main, not Main.


Fixed that problem, so I tried again. It still does the same thing.

I decided to just delete Java and reinstall it. After doing so, the error message is a little longer, but essentially the same.

Here it is.



Now what do I do? :<

I'm completely lost, and this is seriously turning me off Java.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

What did you do to make it look for a class named "main"? Your class is named "VolcanoApplication", so that's what you need to run.
Patches O'Connell
Greenhorn

Joined: Oct 27, 2011
Posts: 5
I'm not sure, this is a verbatim copy of the code that "Sams Learn Java in 21 Days" said to write. I'm literally day 1, so I haven't really done anything besides what it told me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I wasn't asking about the code. I was asking about what you did to cause that error message to show up on your screen.

(By the way: a lot of Java beginners seem to be sensitive about error messages. It's as if error messages were some kind of a put-down telling you that you were a bad or worthless person, or something like that. And it can actually feel that way if you keep getting error messages all the time. But it's not supposed to be like that. Remember the computer isn't your instructor or your mother or the police, it's just a machine which is working for you. So there's nothing personal about error messages; when you get one, read it, because it's supposed to tell you what went wrong. And I can tell you that you're going to get lots more error messages. That's just the way it is when you're a programmer. Read them, deal with them, and move on.)
Patches O'Connell
Greenhorn

Joined: Oct 27, 2011
Posts: 5
Paul Clapham wrote:I wasn't asking about the code. I was asking about what you did to cause that error message to show up on your screen.

(By the way: a lot of Java beginners seem to be sensitive about error messages. It's as if error messages were some kind of a put-down telling you that you were a bad or worthless person, or something like that. And it can actually feel that way if you keep getting error messages all the time. But it's not supposed to be like that. Remember the computer isn't your instructor or your mother or the police, it's just a machine which is working for you. So there's nothing personal about error messages; when you get one, read it, because it's supposed to tell you what went wrong. And I can tell you that you're going to get lots more error messages. That's just the way it is when you're a programmer. Read them, deal with them, and move on.)


Oh, don't worry. I program Perl and Python, so I know error messages aren't the end of the world, but I've been running into error after error since I started the java, and it's only the first snippet of code. So yeah, programming isn't new to me (Perl for like 8 years), but Java very much so is, so naturally it brings me to frustration easier because I've no idea how to fix the error when in one of my native languages it would be trivial. Not to mention I've had a bad day with Github and its many annoyances over the past couple days :P

The way I'm triggering this message is with two methods: First, Eclipse->Run. Second, with the main Java executable. java VolcanoApplication.class
Patches O'Connell
Greenhorn

Joined: Oct 27, 2011
Posts: 5
I made headway. I'm not sure how this fix worked, but I figured...hey...why not. Maybe some one can explain to me why this worked in the first place, and if I'll have to do it exactly like this for every project.
It works now though, which is nice. Picture incoming. Sorry for it being so large, but it doesn't scale with the img tag.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
Please avoid screenshots; they are more difficult to read than copy-and-paste.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7781
    
  21

Patches O'Connell wrote:I made headway...

Great. Slightly off-subject: I'd be suspicious of any book that calls itself "Java in 21" anything (except maybe 'years'). This page backs me up.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
I have a copy of a SAMS Java™ in 21 days book, and I don’t like it.

And compiler errors are your friend. They are a way of picking up mistakes at an early stage, before they have a chance to do any harm.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sams Java in 21 Days java.lang.NoClassDefFoundError: main