P
Perfect Reign
I'm sure I'm doing something wrong but I cannot find out what. After two
hours of googling and even asking a few co-workers, I give up. What's going
on??
I consistently get this message:
non-static method init() cannot be referenced from a static context
From what I understand, I cannot do something non-static from a static
context. Okay, so I want to write a console app which allows for user
interaction. If I call a method which takes a parameter then I get this
mesage. My latest attept is to put the parameter methods in a non static
public method. But then I can't call this from main either. What's going
on?? If - as in the code below - put the call to init() in main, main
gives me the compile method. If it take it out, then I get nothing. If I
get rid of init and put the code in main, I get a similar compile method.
What do I do??
public class myClass
{
public static void main(String[] args)
{
myClass init = new myClass();
init();
}
public void init() throws Exception
{
//get us out of a static method
String strSearch = "something"
if ( searchFile( strSearch ) == true )
{
//do something here
}
else
{
System.out.println( "No Results Found" );
}
}
private boolean searchFile( String strSearch )
{
//method to search for a string
System.out.println( "You searched for: " + strSearch );
return searchFile;
}
}
--
kai - (e-mail address removed) - www.perfectreign.com
kai:/> format a:
Error: The DOS concept of formatting disk media is screwed.
To format a floppy, use "fdformat /dev/fd0"
and then "mkfs.minix /dev/fd0".
hours of googling and even asking a few co-workers, I give up. What's going
on??
I consistently get this message:
non-static method init() cannot be referenced from a static context
From what I understand, I cannot do something non-static from a static
context. Okay, so I want to write a console app which allows for user
interaction. If I call a method which takes a parameter then I get this
mesage. My latest attept is to put the parameter methods in a non static
public method. But then I can't call this from main either. What's going
on?? If - as in the code below - put the call to init() in main, main
gives me the compile method. If it take it out, then I get nothing. If I
get rid of init and put the code in main, I get a similar compile method.
What do I do??
public class myClass
{
public static void main(String[] args)
{
myClass init = new myClass();
init();
}
public void init() throws Exception
{
//get us out of a static method
String strSearch = "something"
if ( searchFile( strSearch ) == true )
{
//do something here
}
else
{
System.out.println( "No Results Found" );
}
}
private boolean searchFile( String strSearch )
{
//method to search for a string
System.out.println( "You searched for: " + strSearch );
return searchFile;
}
}
--
kai - (e-mail address removed) - www.perfectreign.com
kai:/> format a:
Error: The DOS concept of formatting disk media is screwed.
To format a floppy, use "fdformat /dev/fd0"
and then "mkfs.minix /dev/fd0".