Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:23:41+00:00 2026-06-09T23:23:41+00:00

I am using parcel to cache Items in binary file. Everything was fine until

  • 0

I am using parcel to cache Items in binary file. Everything was fine until I need to store into single ArrayList various type of objects:

        fout = new FileOutputStream(file);

        Parcel parcel = Parcel.obtain();
        ArrayList<Object> list = new ArrayList<Object>(items);
        Log.d(TAG, "write items to cache: " + items.size());
        parcel.writeList(list);
        byte[] data = parcel.marshall();
        fout.write(data);

But reading don’t work properly:

fin = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
fin.read(data);
Log.d(TAG, "file size: " + file.length());

Parcel parcel = Parcel.obtain();
parcel.unmarshall(data, 0, data.length);

ArrayList<Object> rawList = parcel.readArrayList(Object.class.getClassLoader());

I think problem is in Object classLoader, who can’t create object for extended class.

Have any idea how I can easily fix this? Or maybe could somebody to give me advise for my task which is to cache ArrayList or Set into file with objects of type <? extends Object?>.
Logcat:

08-20 12:16:52.200: D/ItemList(6637): writing data
08-20 12:16:52.200: D/ItemList(6637): write items to cache: 2
08-20 12:17:45.940: D/ItemList(6925): reading data
08-20 12:17:46.650: D/ItemList(6925): reading data
08-20 12:17:47.050: D/ItemList(6925): reading data
08-20 12:17:47.060: D/ItemList(6925): cache file found
08-20 12:31:18.050: D/ItemList(7349): file size: 760
08-20 12:17:47.060: D/ItemList(6925): founded items in cache: 0

More logcat:

08-20 12:49:02.930: D/ItemList(9241): file size: 1136
08-20 12:49:02.930: D/ItemList(9241): dataAvail(): 0
08-20 12:49:02.930: D/ItemList(9241): dataSize(): 1136
08-20 12:49:02.930: D/ItemList(9241): dataCapacity(): 1136
08-20 12:49:02.930: D/ItemList(9241): founded items in cache: 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:23:42+00:00Added an answer on June 9, 2026 at 11:23 pm

    OK, I found it. You never read the data from the file:

    fin = new FileInputStream(file);
    byte[] data = new byte[(int) file.length()];
    

    All you do is create the input stream and allocate a byte buffer.

    EDIT Add more code about how to unmarshall the Parcel

    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(data, 0, data.length);
    parcel.setDataPosition(0); // Set the position in the parcel back to the beginning
                               //  so that we can read the stuff out of it
    ArrayList<Object> rawList = parcel.readArrayList(Object.class.getClassLoader());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
I'm trying to write an array of objects that implement Parcelable into a Parcel
Using gcc and ld on x86_64 linux I need to link against a newer
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using SQL Server 2008 R2 we are looking for a way to select the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.