execute non-static method in main()

hi,

i'd encounter a serious problem and urgently need to know how to solve this problem. for simplicity the problem i use the following illustration.

class testing

{

void test()

{

System.out.println( "1234" );

}

public static void main( String[] args )

{

test();

}

}

when i compile this file, it return following error message:

non-static method test() cannot be reference from a static context...

how to solve this problem ? anybody have any idea or suggestion? in my case, i have to use some non-static methods( form other classes ) in the main() ~~@_@~~

[660 byte] By [bluehappo] at [2007-9-27 20:23:10]
# 1
Create an object ;)testing t = new testing();t.test();And read the tutorials.
phohmeyer at 2007-7-7 0:52:40 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

Trying to remain as congnial as possible, your first advice is very good and concise. Perhaps the clearest answer that I had read (because it's so simple) on this problem, which according to a few people is one of the most typical problems encountered by people new to java.

Which is why your advice "And read the tutorials. " is so frustrating to read.

http://developer.java.sun.com/developer/onlineTraining/ has a lot of tutorials on a lot of subjects, and frankly this doesn't seem to be covered as such in any of them via a cursory glance.

This doesn't mean that you shouldnt recommend the tutorials. I would suggest only that you recommend reading a specific section of a specific tutorial.

Not as easy as saying "And read the tutorials," but certainly more helpful.

illovich at 2007-7-7 0:52:40 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

> class testing

> {

>void test()

>{

>System.out.println( "1234" );

>}

>public static void main( String[] args )

>{

>test();

>}

> }

Just make it this:class testing {

// this needs to be a static method for main() to access it

static void test() {

System.out.println("1234");

}

public static void main(String[] args) {

test();

}

}

-Woogley

Woogley at 2007-7-7 0:52:40 > top of Java-index,Archived Forums,New To Java Technology Archive...