Need help with usage of static functions

Hi,

I tried instantiating objects within static functions as follows: It gives error:

If someone can explain an alternate way of doing things, I would appreciate:

public class C {

/**

* @param args

*/

public static void main(String[] args) {

Y.Fn1();

}

}

public class X {

public void Fn2(){

int b=2;

System.out.println("hello");

}

}

public class Y {

public static void Fn1()

{

int a=2;

X obj = new X();

obj.Fn2();

}

}

The actual error is:

Cannot make a static referencxe to the nonstatic method Fn2() from the type X Y.java

Need Help : If someone can comment on the following, I would appreciate:

I have a class Session, which has a method ProcessEvent()

public class Session{

public synchronized void processEvent(Event e)

{

// Processing of the event

// Generate a response for the Event

}

}

This Session class is the mainstream code..

Now I want to write a TestClass that will test the main code.

So I have a Test class as below:

public class Test {

public static void sendReq()

{

// Construct an event and call processEvent Function from the main code

Event ev = new Event();

// Fill the event with parameters

..

Session sess = new Session();

sess.processEvent(ev);

}

}

What I am thinking of doing is: Call the static method in another class called Manager of the mainstream code for test purpose as follows:

public class Manager {

public void somefunction()

{

//*** Just for test purpose: do the following line **//

Test.sendReq();

}

}

I am not sure what I am trying to do will work. I would appreciate if you can comment on that or suggest something that would work for me.

Another thing which I want to do is:

Inside ProcessEvent(), I want to call another static method ParseandValidateResponse() of the TestClass This looks odd, but as long as it works, it would be fine for me because this is only for test purpose.

In this case, I would write,

public class Session{

public synchronized void processEvent(Event e)

{

// Processing of the event

// Generate a response for the Event

Test.parseandValidateResponse(Response res);

}

public class Test {

public static void sendReq()

{

// AS SHOWN PREVIOUSLY

}

public static void parseandValidateResponse(Response resp)

{

// validate the response

}

}

[2678 byte] By [mnasjsua] at [2007-11-27 10:17:47]
# 1

Cross post

http://forum.java.sun.com/thread.jspa?threadID=5193837

Why litter up the forums? Did you read my reply in the last thread?

_helloWorld_a at 2007-7-28 15:53:43 > top of Java-index,Java Essentials,New To Java...
# 2

Sorry I thought no one had replied. When I posted here, I missed seeing yr reply. Later just now I saw yr reply It was in the second Page

(Earlier I was looking only in first page by mistake)

Meena

mnasjsua at 2007-7-28 15:53:43 > top of Java-index,Java Essentials,New To Java...