Problem with storing Object in to file

Put your problem here if it does not fit any of the other categories.

Problem with storing Object in to file

Postby naveenballa » Wed Nov 25, 2009 6:58 am

I have a class like

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    static class MyData implements Serializable{  
  2.  
  3.         public MyData(String n, String ed, String d,Location[] locarr,int size,boolean e) {  
  4.  
  5.             name = n;
  6.  
  7.             end = ed;
  8.  
  9.             desc = d;
  10.  
  11.             locarray=locarr.clone();
  12.  
  13.             arrsize = size;
  14.  
  15.             enable = e;
  16.  
  17.         }  
  18.  
  19.         String name;
  20.  
  21.         String end;
  22.  
  23.         String desc;
  24.  
  25.         Location[] locarray;
  26.  
  27.         int arrsize;
  28.  
  29.         boolean enable;
  30.  
  31.     }
  32.  
  33.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


i tried to store the objects in file, the location array is not storing into file

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.           public static List<MyData> mObjectList = new ArrayList<MyData>();      
  2.  
  3.             outputStream = new ObjectOutputStream(new FileOutputStream("/sdcard/tripdata"));
  4.  
  5.             int i=0;
  6.  
  7.             while(i<mObjectList.size()) {
  8.  
  9.                 outputStream.writeObject(mObjectList.get(i));
  10.  
  11.                 i++;
  12.  
  13.             }
  14.  
  15.  
  16.  
  17.             inputStream = new ObjectInputStream(new FileInputStream("/sdcard/tripdata"));
  18.  
  19.            
  20.  
  21.             Object obj = null;
  22.  
  23.            
  24.  
  25.             while ((obj = inputStream.readObject()) != null) {
  26.  
  27.                
  28.  
  29.                 if (obj instanceof Mydata1) {
  30.  
  31.                         mObjectList.add((MyData)obj);
  32.  
  33.                 }
  34.  
  35.                
  36.  
  37.             }
  38.  
  39.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


can anyone tell me how to store the location array objects
naveenballa
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 16, 2009 12:53 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests