ClassNotFoundException in an object conversion

I've been reading the forums for a solution to this problem, but I haven't been able to - be gentle. :P

I'm trying to implement my own networking package that mimics the SQL API already implemented. I know you're asking why, so, the reason is, I'm developing software for a handheld that needs more fault tolerance than the package provides.

Anyway, so, basically, I'm using buffered streams over a socket to transmit an SQL request as a string. Then I transmit back the results in my own Results class (No need to worry about how it's implemented, that works fine). The Results class implements Serializable.

I use this static method to rebuild my objects after transmission:

publicstatic Object byteArrayToObject(byte[] data)throws IOException, ClassNotFoundException

{

ByteArrayInputStream bis =new ByteArrayInputStream(data);

ObjectInputStream ois =new ObjectInputStream(bis);

Object temp = ois.readObject();

ois.close();

bis.close();

return temp;

}

The strange thing about this is, I have only three types of actions my NetSQLClient class can take. NetSQLClient.executeQuery(String), NetSQLClient.executeUpdate(String) and NetSQLClient.execute(String). They all behave similary to the equivalent methods from Statement.

In all other places where I execute NetSQLClient.executeQuery(String), it works fine. I can query a user table for authentication, I can query my field information to build the UI, etc. But in one place, I get a ClassNotFoundException on a query. Here's the process:

Private class within the Client class:

privateclass SocketReaderimplements Runnable

{

BufferedInputStream in;

public SocketReader(InputStream input)

{

in =new BufferedInputStream(input);

}

publicvoid run()

{

while(running)

{

try

{

byte[] size =newbyte[4];

in.read(size);

int incomingSize = Convert.byteArrayToInt(size);

if(incomingSize == 0)

{

disconnect();

}

else

{

byte[] data =newbyte[incomingSize];

in.read(data);

if(listener !=null)

{

byte[] trans =newbyte[data.length];

System.arraycopy(data, 0, trans, 0, trans.length);

listener.dataRecieved(trans);

}

}

}

catch(IOException e)

{

running =false;

break;

}

}

}

}

The above is a private class that is a simple recieve thread. The listener is an interface I made so data can be transmitted out of the Client class. It goes here, in the NetSQLClient class:

publicsynchronizedvoid dataRecieved(byte[] data)

{

this.data = data;

notify();

}

The part of NetSQLClient that is waiting:

publicsynchronized Results executeQuery(String query)throws NetSQLException

{

try

{

client.write(101);

client.write(query);

wait();

return (Results)Convert.byteArrayToObject(data);

}

catch(InterruptedException e)

{}

catch(IOException e)

{

thrownew NetSQLException("Internal I/O error.");

}

catch(ClassNotFoundException e)

{

thrownew NetSQLException("Internal class error.");

}

catch(ClassCastException e)

{

try

{

throw (NetSQLException)Convert.byteArrayToObject(data);

}

catch(IOException ef)

{

thrownew NetSQLException("Internal IO error type 2.");

}

catch(ClassNotFoundException ef)

{

thrownew NetSQLException("Internal class error type 2.");

}

catch(ClassCastException ef)

{

thrownew NetSQLException("Internal casting error.");

}

}

returnnull;

}

As you can see, this is where I call Convert.byteArrayToObject(byte[] data). And this is where the exception is generated in only one circumstance. Here's is the code that calls it, although I dunno how it's different from any other place I call that method:

Results rs = client.executeQuery("SELECT * FROM serial_asset WHERE asset_number = '" + serial +"';");

Anyway, any help would be appreciated. I have no idea what's going on anymore.

[7634 byte] By [Nova_Collisiona] at [2007-10-3 8:09:42]
# 1

In the code:

Results rs = client.executeQuery("SELECT * FROM serial_asset WHERE asset_number = '" + serial + "';");

What is the serial object?

I would like to be more helpful but you have not included much of the relavent code nor have you included the full stack trace of the error message.

zadoka at 2007-7-15 3:13:59 > top of Java-index,Core,Core APIs...
# 2
serial is just a string. That's an SQL statement that is just transmitted back to the bridge.I can't include a stacktrace as everything works fine on a desktop and the handheld has no way of printing a stacktrace.
Nova_Collisiona at 2007-7-15 3:13:59 > top of Java-index,Core,Core APIs...
# 3
> I can't include a stacktrace as everything works fine> on a desktop and the handheld has no way of printing> a stacktrace.That is a very important fact that you left out in the orginal question.
zadoka at 2007-7-15 3:13:59 > top of Java-index,Core,Core APIs...
# 4
Well, I apologize for the desktop thing, but I don't see how a lack of error reporting in the handheld is relevant to the problem at hand.Anyway, it seems this is the wrong place for this question - the error is probably platform dependant.
Nova_Collisiona at 2007-7-15 3:13:59 > top of Java-index,Core,Core APIs...
# 5

> Well, I apologize for the desktop thing, but I don't

> see how a lack of error reporting in the handheld is

> relevant to the problem at hand.

The lack of error reporting is not a problem it is that it worked on one OS and not the other.

> Anyway, it seems this is the wrong place for this

> question - the error is probably platform dependant.

Agreed, you might have better luck in another forum. If you create a new topic link to if from here in case someone here can help.

zadoka at 2007-7-15 3:13:59 > top of Java-index,Core,Core APIs...