Question

Hello all having some trouble when I attempt to add an image to a viewflipper page, I am pulling the bitmaps from the db4o database (not sure if it is the encoding or something it uses that is messing me up).

private void setImageView() {
    page = (ViewFlipper) findViewById(R.id.viewFlipper1);

    int temp = DigPlayDB.getInstance(getBaseContext()).getPlaysDBSize();

    for(int j = 0; j < temp; ++j){
        test.add(DigPlayDB.getInstance(getBaseContext()).getPlayByInt(j).getImage());
        test1.add(DigPlayDB.getInstance(getBaseContext()).getPlayByInt(j).getPlayName());
    }

    for(int i=0;i<temp; i++)
    {
        //  This will create dynamic image view and add them to ViewFlipper
        setFlipperImage(test.get(i));
    }

And then for the setting of the image and adding the view to the page

private void setFlipperImage(Bitmap image){
    ImageView _image = new ImageView(getApplicationContext());
    //_image.setBackgroundDrawable(new BitmapDrawable(getResources(), image));
    _image.setImageBitmap(image);
    page.addView(_image);
    Log.d("db", "" + image);

} 

It works right after I add an image to the database but just that image, older images as well as when I restart the application do not load up even though it says they do from a debugging log I set. I am thinking that the last one shows up since it could still be in a cache somewhere, but the older ones that are stored in the database and not in a cache are not encoded correctly or something. Any help would be awesome. Thanks!

Edit: I should mention that "test" is an arraylist of Bitmaps.

Was it helpful?

Solution

Ok, you said in the comment that you store the object as a Bitmap instance. I guess thats a Android or library class.

Don't do that. Only store instances of your own classes. Storing instances of your classes, java.util.collections, arrays and primitives are okay. Everything else is bound to issues: db4o will eagerly try to store any object. This is a issue for library instances. You don't have control of what they do, how they work internally and if they still work after loading.

I think that's whats happening here. As long as the application is running, db4o returns the cached instance of the object, which is fine. After restarting the application, db4o loads the Bitmap object. However the bitmap object isn't intended to be stored with db4o, so it stumbles over wrongly stored internal state.

So, store your picture in a byte-array. Or just as plain file on the SD-card.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top