File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Should this code work in NetBeans? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Should this code work in NetBeans?" Watch "Should this code work in NetBeans?" New topic
Author

Should this code work in NetBeans?

andrew dale
Ranch Hand

Joined: Aug 15, 2011
Posts: 45
Heres the code:



It was part of Head First Java book, code magnet test chapter 2.

I also have a question or two about it:

boolean Tophat = true;
boolean snare = true;

I thought boolean was just to get a True/False answer... What does that mean when you making it = to true?

Thank you. This forum and everyone apart of it has been a godsend to me.

edit-------

This is what I get when I run the project


run:
java.lang.NoSuchMethodError: main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

You'll never achieve your goals if you don't take that chance, so go pry open that trunk and get those amps.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32604
    
    4
Yes, you can set a boolean to true or false like that.

I would prefer to see if (b) ..., not if (b == true) ... ==true and ==false should never, in my opinion, be used.

You would need a class with a main method, and the main method calls the other code.
andrew dale
Ranch Hand

Joined: Aug 15, 2011
Posts: 45
Campbell Ritchie wrote:Yes, you can set a boolean to true or false like that.

I would prefer to see if (b) ..., not if (b == true) ... ==true and ==false should never, in my opinion, be used.

You would need a class with a main method, and the main method calls the other code.


Ok, so you cant get the true/false result without boolean is that what your saying?

I also don't understand what you mean by I need a class with a main method? Do i have to create a separate file? If you can elaborate it would be greatly appreciated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

andrew dale wrote:This is what I get when I run the project


run:
java.lang.NoSuchMethodError: main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

That's probably because you are trying to run class DrumKit, whereas you should run class DrumKit.DrumKitTestDrive - that's the class with the main method.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Campbell Ritchie wrote:
I would prefer to see if (b) ..., not if (b == true) ...

Correct! because sometime by mistake you may type if(b = true) and also if(b) is looks better than if(b == true) . is not it?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32604
    
    4
andrew dale wrote: . . . Ok, so you cant get the true/false result without boolean is that what your saying? . . .
Not at all. The reserved words true and false are boolean literals, which means they count as booleans themselves.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Did you really mean to put the class DrumKitTestDrive inside class DrumKit, or is that a mistake?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should this code work in NetBeans?
 
Similar Threads
Method help: how does this work?
Boolean question
class and testclass
Head First Exercise Pg 43
Head First Java Beginnner's Question