This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I try to compile the code with the netbeans compiler
I got an error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context
at javaapplication2.Main.main(Main.java:23)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
It's the code of the book of head first java. can someone tell me what I am doing wrong?
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
posted
0
The code you posted is not what is in Head First Java. You have the Book and BooksTestDrive classes as inner classes to Main, which is not how it is on pg. 63, and I'm not even sure what you've posted will compile because you are missing a }.
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Frank Thuring
Greenhorn
Joined: Aug 10, 2010
Posts: 28
posted
0
Hi Joe,
I saw I missed a }
on page 68 of the second edition is the solution of the problem.
Now I got another error can you help me?
the error is : java.lang.NoSuchMethodError: main
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
posted
0
I'm still confused as to why you have everything wrapped in a class called Main. It isn't needed, nor is it in the book. I'm not trying to be mean or anything, just trying to understand your thinking.
As for your error, from the command line run it as java BooksTestDrive. You should run the class that has the main method in it.
Frank Thuring
Greenhorn
Joined: Aug 10, 2010
Posts: 28
posted
0
Hi Joe,
can you give me a clue with the main how you would programm this ?
Frank Thuring
Greenhorn
Joined: Aug 10, 2010
Posts: 28
posted
0
Hi Joe,
can you give me a clue with the main how you would programm this ?
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
posted
0
Normal javaranch policy is to not give out code, but since this is from the book you are using, here is the code from HFJ:
From there, I'd just compile it using javac <FileName>.java, then run it using java BooksTestDrive.
Timothy Onggowasito
Greenhorn
Joined: Apr 16, 2010
Posts: 11
posted
0
I think it has something to do with netbean. They ussualy added the main class in the beginning as a template.
Try using Dr. Java as a compiler. It's much simpler to use.
Apparently, what you don't know can hurt you...
Tim Ong