[SOLVED] Multi-dimensional Array further help
Hi
I have managed to send the multi-dimensional array to the client, the only problem is I am now trying to make use of the sent Object as follows:-
import java.io.*;
import java.net.*;
import java.util.Scanner;
import java.nio.*;
import java.util.*;
public class TCPclient
{
public static void main(String[] args)
{
// Declare client socket
Socket clientSocket = null;
Scanner myScanner = new Scanner(System.in);
// Declare output stream and string to send to server
DataOutputStream os = null;
int request;
int n = 0;
Object A[][] = new Object[n][n];
// Declare input stream from server and string to store input received from server
BufferedReader is = null;
int responseLine;
int b;
InputStream in;
ObjectInputStream recieve;
Object recieved;
Object recievedB;
Object c;
// Create a socket on port 1024
//Stream header
try
{
clientSocket = new Socket("localhost", 1024);
os = new DataOutputStream(clientSocket.getOutputStream());
is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
catch (UnknownHostException e)
{
System.err.println("Don't know about host: hostname");
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection to: hostname");
}
// Write data to the socket
if (clientSocket != null && os != null && is != null)
{
try
{
request = 0;
os.writeInt(request);
in = clientSocket.getInputStream();
recievedFrom = new ObjectInputStream(in);
while(request != 1)
{
responseLine = is.read();
b = responseLine;
System.out.println("Client b " + b + "\n");
request++;
recieved = recieveFrom.readObject();
recievedB = recieveFrom.readObject();
System.out.println(recieved);
System.out.println(recievedB);
A[n][n] = recieved;
}//end while
// Close the input/output streams and socket
os.flush();
is.close();
clientSocket.close();
}//end try
catch (UnknownHostException e)
{
System.err.println("Trying to connect to unknown host: " + e);
}
catch (IOException e)
{
System.err.println("IOException: " + e);
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
}//end if
}
}
The variable recieved holds the contents of readObject(), this recieves the Object from the Server. I have created the variable A[n][n] which is to store the result of recieved. I have implemented A[n][n] = recieved inside of the while() loop, but get the following exception message
[[Ljava.lang.Object;@14318bb
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at TCPclient.main(TCPclient.java:83)
therefore I know that the Object is being recieved, but the A[n][n] = recieved; is not liked, it will compile, but the Exception is thrown. I am trying to get the value of A[n][n] for use outside of the loop for further calculations. An advice on how I could do this would be apprciated.
theLinuxGuy