Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threads and classes

Status
Not open for further replies.

richATrichardjones

Technical User
Sep 22, 2002
24
GB
Hi

I have four classes in my prog. The first one is called MainProg.java and it coordinates the other three. The next one is called ProxyServer.java. It will eventually be a proxy server but at the moment all it does is return an array of size 4 of integers. The next is called ClientGUI.java which makes the GUI appear on the screen. The next is histogram.java which takes teh array from ProxySever.java and make a histogram of it. Without ProxyServer it works fine. With proxyServer only returning a single number (instead of an array) it works fine. However when it return an array it says there is a thread exception so doesnt even get to the ClientGUI and Histogram code.

To be clearer the order of events (all within main in MainProg.java) is as follows:

MainProg.java
|
|
|---- ProxyServer.java
|
|---- ClientGUI.java
|
|-----Histogram.java

The code in MainProg that calls ProxyServer is as follows:

ProxyServer myProx = new ProxyServer();
temp = ProxyServer.getArray();

The error is on the first line.

The code for ProxyServer is:

class public ProxyServer{

private int[] myArray;

public ProxyServer()
{
myArray[0] = 100;
myArray[1] = 100;
myArray[2] = 100;
myArray[3] = 100;
};

public int[] ProxyServer.getArray()
{
return myArray;
}
}


The error seems really odd. Like I said earlier the code all works when ProxyServer returns a single value but I get a thread exception when it returns and array.

Thanks for any help

Richard
 
Hi,

you need to construct your array with....

myArray = new int[4];

in your ProxyServer() constructor before you assign values to it.

Also, you should probably declare
public int[] ProxyServer.getArray()
as
public int[] getArray()
(I'm assuming that long-term, you don't intend it to be a static method) and then reference it in MainProg like:
temp = myProx.getArray();

Hope that helps,
Lloyd

 
Thanks for the reply LloydV. I havent tried it but if it works it will help greatly

Cheers again

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top