Hashtable Serialization (Server/Client App)

by nsyed » Wed, 14 Apr 2010 03:38:47 GMT


Sponsored Links
 Hi All,

I am having a weird issue with serialization of a Hashtable. I have
made a Server, Client app. Where server(PC/MAC) is serializing a
Hashtable and sending it to Client(Android) through UDP. The data is
sent/read correctly but I get a bunch of these messages below on
LogCat.

04-12 11:19:43.059: DEBUG/dalvikvm(407): GetFieldID: unable to find
field Ljava/util/Hashtable;.loadFactor:F

Occasionally, I would see these

04-12 11:21:19.150: DEBUG/dalvikvm(407): GC freed 10814 objects /
447184 bytes in 97ms

The app would run for 2-3 mins and then crash. Interestingly enough I
do not see the Loadfactor errors on SDK 1.5. But I do see the GC Free
xxxx objects, quiet often.

After debugging I have found that the issue is with de-serialization
and the error/warning are coming from following code

Code:

ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
object = ois.readObject();
at Code:

object = ois.readObject();
on the client. My server is serializing code is the following.

Code:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
Any idea what is going on?

Thanks for the Help!

--



Hashtable Serialization (Server/Client App)

by Bob Kerns » Thu, 15 Apr 2010 01:23:50 GMT


 I don't have a solution, but I have a couple of recommendations --
either of which would avoid the problem.

#1 - don't use object serialization. Convert to an XML or JSON
representation instead. XML in particular would be preferred if you're
going to store these for an extended time.

#2 -- don't use Hashtable. It is a holdover from the early days of
Java, but it has inappropriate synchronization on various methods.
Use HashMap instead. This won't usually result in any other changes to
your code. If you were depending on the method synchronization of
Hashtable, you should take a good look at your code; it's likely you
weren't doing it right, and synchronizing on the table (or a larger-
scoped object) across a larger set of operations will fix bugs you may
not know you have. The synchronizing built into Hashtable is seldom
the actual synchronization needed!

Nothing in your message really suggests that your crash is related to
the message about serialization. If the loadfactor for the Hashtable
is set to zero, I suspect that would cause problems, but if it ends up
initialized to some reasonable default, this would be harmless. You
could check in the debugger pretty easily

The GC messages are not related to your problem. They indicate that
your program is causing the GC to run; this is of interest for
optimizing or analyzing performance.




--


Sponsored Links


Hashtable Serialization (Server/Client App)

by priyanka » Fri, 23 Apr 2010 13:17:27 GMT


 i All,

I am observing a similar issue. I get structured data from my server
to Android client in XML format. I parse the XML into a HashMap, and
save this HashMap object in file persistent storage. Now, when I
retrieve this HashMap object saved in file through :
HashMap<String, Object> hashMap = (HashMap<String, Object>)
objectInputStream.readObject();

I get
GetFieldID: unable to find field Ljava/util/HashMap;.loadFactor:F


for about 150 times (interspersed with about 2 GC freed commands); and
then I am able to read my object. I am not getting any crash, but I
suppose this might be slowing my app. And I am wondering how I can
resolve this. Any clues would be appreciated.

Thanks,
Priyanka


On Apr 14, 11:30pm, Naqi Syed <naqis...@gmail.com> wrote:
> >



Other Threads

1. Send SMS in Android

hi guys,

i have a application which send sms. but i found that the application
always sends 2 sms messages to the selected number.

couldn't figure out how is this happening. so i'll paste the code
below if you have any suggestions just let me know

public class Compose extends Activity {
   private EditText name, msg;
   private Button send;
   private Spinner spinnerTimer;
   private ImageButton contacts;
   String contactName, number;
   private ImageView shp;
   private HashMap<String, Integer> color;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.compose_sms);
      colorMap();
      name = (EditText) findViewById(R.id.num);
      msg = (EditText) findViewById(R.id.msg);
      send = (Button) findViewById(R.id.snd);
      send.setOnClickListener(new OnClickListener() {

         @Override
         public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d("Button", "Button");
            send("454546", "Mike");
            return;
         }
      });


   }

   public void alert(String header, String body) {
      new AlertDialog.Builder(this).setTitle(header).setMessage(body)
            .setCancelable(true).setNeutralButton("Close",
                  new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog,
                           int which) {
                        // TODO Auto-generated method stub
                     }
                  }).show();
   }






   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
      // TODO Auto-generated method stub
      if (keyCode == KeyEvent.KEYCODE_BACK) {
         finish();
         Intent intent = new Intent(this, Menu.class);
         startActivityForResult(intent, 107);
         return true;
      }
      return false;
   }



   private void send(String number,String msg) {

         PendingIntent pi = PendingIntent.getActivity(this, 0,
                  new Intent(this, Compose.class), 0);
         Log.d("SMS", "SMS");
              SmsManager sms = SmsManager.getDefault();
              sms.sendTextMessage(number, null, msg, pi,
null);

   }
}


regards,
Mike

-- 

2. Making the graphic layer transparent, for video playback

Hi,
I'm porting Android to a board with hardware video decoding support.
The board hardware draws the video into a video layer beneath the
graphic layer. I've implemented a custom media player that passes the
calls to the hardware decoders, but I need to make Android's surfaces
transparent. Is there any way this is possible with the current
Android architecture? I'm using the Eclair version for MIPS
architectures.
Thanks in advance,
 Svetozar

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. deserialize byte[]

4. Creating Menu Problem

5. How to build default applications as a seperate

6. Help: tolong bantu cek hasil ROOT HTC Hero

7. HH android Meizu M