HashMap de-serialization

I have a server / client application where I get data from the server through Hessian / hessdroid. Data is very complex with HashMaps containing other HashMaps and images stored in byte arrays. I can display data perfectly.

To not always query the server, I use the data structure as a cache. I save this data object to the SD card using ObjectOutputStream when closing the application. When I reload it, I read it back into memory using ObjectInputStream.

I have problems with the application only after reading data from the SD card. LogCat gives me the following result (100 times):

DEBUG/dalvikvm(4150): GetFieldID: unable to find field Ljava/util/HashMap;.loadFactor:F

and this between other posts:

INFO/dalvikvm-heap(4150): Grow heap (frag case) to 10.775MB for 281173-byte allocation

When the heap grows at ~ 17 MB, the application crashes.

I read a few threads about HashMap serialization and it seems to be a mistake when serializing between architectures, but for me data transfer through Hessian works fine, and I have the problems described only when reading HashMaps from disk.

Any ideas?

+5
source share
1 answer

The problem is not directly related to the deserialization of HashMap, as the cyber monk commented. There really is some kind of error in Android, or is it an implementation of HashMap, but I don’t think that this is due to the application crashing.

, . , , . .

, .

:

1) ( , )

2) ImageViews .

3) ImageView.

4) ImageView )

5) "" ImageViews, , .

:

// initialize the viewFlipper by creating blank views
for (ComponentImageDto listElement : images) {
    LinearLayout view = renderView();
    flipper.addView(view);
}
showImage(flipper.getCurrentView());

renderView() LinearLayout, ImageView

, / , ImageView:

private void showNextElement() {
    // show next flipper view
    flipper.showNext();

    // get current view
    int displayedChild = flipper.getDisplayedChild();
    View currentView = flipper.getCurrentView();

    // load the binary data
    showImage(currentView);

    // get the next to last view index (if keeping max. 3 images at a time in memory)
    int otherChild = (displayedChild - 2);
    if (otherChild < 0) {
        otherChild = otherChild + flipper.getChildCount();
    }

    // .. and remove it
    removeImage(flipper.getChildAt(otherChild));
}

private void showPreviousElement() {
    flipper.showPrevious();
    int displayedChild = flipper.getDisplayedChild();
    View currentView = flipper.getCurrentView();
    showImage(currentView);
    setTitle((CharSequence) currentView.getTag());
    int otherChild = (displayedChild + 2) % flipper.getChildCount();
    removeImage(flipper.getChildAt(otherChild));
}

private void removeImage(View view) {
    ImageView imageView = (ImageView) view.findViewById(R.id.gallery_image);
    if (imageView != null) {
        imageView.setImageResource(R.color.transparent);
        System.gc();
    }
}

private void showImage(View view) {
    ImageView imageView = (ImageView) view.findViewById(R.id.gallery_image);
    if (imageView != null) {
        bm = BitmapHelper.decodeByteArray(images.get(flipper.getDisplayedChild()).getImage().getBinaryObject());
        imageView.setImageBitmap(bm);
    }
}

- BitmapHelper, stackoverflow, , .

+2

All Articles