I am writing an android client app which sends a Hashtable to a remote servlet and recieves an ArrayList consisting of a custom Object which is serializable. This ran fine when I was just receiving the ArrayList from a java console app. So I know my objects are being serialized and deserialized properly. But when I port the same client code over to android I get an error when trying to read the ArrayList of my objects. Is there any differences in the way Android does serialization? I can't seem to find any documentation that says it does. The error I receive is:
java.lang.IndexOutOfBoundsException: Invalid location
at java.util.ArrayList.get(ArrayList.java:350)
============ My Android Client app is as follows=================================
public class TTCPointService {
private Logger logger;
private FileHandler handler;
public TTCPointService(){
try
{
logger = Logger.getLogger(TTCPointService.class.getName());
handler = new FileHandler("ttcservice.log");
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);
}
catch(IOException e)
{
logger.log(Level.SEVERE,e.toString());
}
}
public ArrayList<Stop> ConnectToServlet()
{
ArrayList<Stop> list = new ArrayList<Stop>();
Hashtable<String, String>obj = new Hashtable<String,String>();
obj.put("lat", "12.00");
obj.put("log", "-23.00");
try
{
URL servletURL = new URL("http://10.0.2.2:8080/GTFSProcessor/TTCPoints");
HttpURLConnection servletConnection = (HttpURLConnection)servletURL.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setDoInput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");
servletConnection.setRequestMethod("POST");
logger.log(Level.INFO,"Connecting to Servlet");
//Send object to servlet
OutputStream os = servletConnection.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(obj);
oos.flush();
oos.close();
logger.log(Level.INFO,"Hashtable sent to Servlet");
//Read from servlet
InputStream is = servletConnection.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is);
list = (ArrayList<Stop>)ois.readObject();
logger.log(Level.INFO,"Reading Object from Servlet");
os.close();
}
catch(IOException e)
{
logger.log(Level.SEVERE,e.toString());
}
catch(ClassNotFoundException e)
{
logger.log(Level.SEVERE,e.toString());
}
return(list);
}
}
=============The code that raises the error is===================================
ArrayList<Stop> list = new ArrayList<Stop>();
TTCPointService service = new TTCPointService();
list = (ArrayList<Stop>)service.ConnectToServlet();
Toast.makeText(mapView.getContext(), "list contains: "+list.get(0).getName(), Toast.LENGTH_SHORT).show();




