Below is some test code that works fine when run from the command line
(it prints out a phone number five times).
However, when I run this same code from within my android app, it
fails on every other call to “getit()”. Specifically, it fails on
this line:
inStream = new ObjectInputStream ( url.openStream() );
with a java.io.StreamCorruptedException. I have checked for version
differences in the java sdk, but that checked out okay.
How can I further track down the source of this error, which is
apparently specific to the android environment?
DanaH
_____________________________________________
import java.net.*;
import java.io.*;
import java.util.*;
import java.beans.*;
public class discHashTest {
public static void main ( String args[] ) {
discHashTest x = new discHashTest();
x.go ();
}
public discHashTest () {}
public void go () {
URL url = null;
try {
url = new URL ( MY_SERVLET_URL);
} catch (Exception e) {
System.out.println ( "Died trying to read" );
e.printStackTrace ();
}
getit ( url );
getit ( url );
getit ( url );
getit ( url );
getit ( url );
}
private void getit ( URL url ) {
ObjectInputStream inStream;
try {
inStream = new ObjectInputStream ( url.openStream() );
HashMap h = (HashMap) inStream.readObject();
inStream.close();
Vector v = (Vector) h.get ( "LMRCH" );
HashMap h1 = (HashMap) v.elementAt ( 0 );
System.out.println ( h1.get ( "phone" ) );
} catch (Exception e) {
System.out.println ( "Died trying to decipher" );
e.printStackTrace ();
}
}
}
_____________________________________________
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en