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 non-static method nextBoolean() cannot be referenced from a static context error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-static method nextBoolean() cannot be referenced from a static context error" Watch "non-static method nextBoolean() cannot be referenced from a static context error" New topic
Author

non-static method nextBoolean() cannot be referenced from a static context error

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

error:

What is wrong and how can I fix it? initdir and upslashdown are of String type FYI.
Thanks,
cc11rocks


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19060
    
  40

john price wrote:error:

What is wrong and how can I fix it? initdir and upslashdown are of String type FYI.
Thanks,
cc11rocks


Basically, the nextBoolean() method is *not* a static method. You need to have an instance of the Random object to call it -- you just can't specify it with the Random class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Thank you very much. All i had to do was add:

Then I changed it to:

Thanks so much!
John Price aka cc11rocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: non-static method nextBoolean() cannot be referenced from a static context error