File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should this code work in NetBeans?

 
andrew dale
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you really mean to put the class DrumKitTestDrive inside class DrumKit, or is that a mistake?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic