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 6775573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:55:21+00:00 2026-05-26T15:55:21+00:00

I have a question about parcelable class (android). Until now, I have passed a

  • 0

I have a question about parcelable class (android).

Until now, I have passed a DoubleArray between 2 Intent whithout any problem:

new double[] latLong = new double[]{loc.getLatitude(),loc.getLongitude()};
...
intent.putExtra(Site.LATTITUDE, latLong);   
...
startActivityForResult(intent, this.ACCESS_GOOGLE);

Today, I tried to add new data for the same activities using parcelable class.
My parcelable class:

package common;

import android.os.Parcel;
import android.os.Parcelable;

public class Site implements Parcelable {

    private int id;
    private String site_name;
    private int category ;
    private double latitude;
    private double longitude;

    /**
     * 
     * @param id
     * @param site_name
     * @param category
     */
    public Site(int id, String site_name, int category,double latitude, double lonngitude){
        this.id=id;
        this.site_name=site_name;
        this.category=category;
        this.latitude=latitude;
        this.longitude=longitude;

    }

    public Site(Parcel in){
        readFromParcel(in);
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.site_name);
        dest.writeInt(this.category);
        dest.writeDouble(this.latitude);
        dest.writeDouble(this.longitude);
    }


    /**
     * 
     * @param in
     */
    private void readFromParcel(Parcel in) {        
        this.id     = in.readInt();
        this.site_name  = in.readString();
        this.category   = in.readInt();
        this.latitude   = in.readInt();
        this.longitude  = in.readInt();
    }


   public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {

            public SiteGoogle createFromParcel(Parcel in) {
                return new Site(in);
            }

            public SiteGoogle[] newArray(int size) {
                return new Site[size];
            }
        };


    /* GETTER / SETTER */

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSite_name() {
        return site_name;
    }

    public void setSite_name(String site_name) {
        this.site_name = site_name;
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

}

I put some Site objects(above class) in a java ArrayList, and pass this list to my second Activity with the below code :

ArrayList<Site> sitesForMap = new ArrayList<Site>();

for(int i=0; i<sites.size();i++){

    SiteGoogle site = new SiteGoogle(
            sites.get(i).getId(),
            sites.get(i).getSite_name(),
            sites.get(i).getCat(),
            sites.get(i).getLatitude(),
            sites.get(i).getLongitude());

    sitesForGoogle.add(site); 
}

//put data in the intent
intent.putExtra(Site.LATTITUDE, latLong); //first data that worked well until now
intent.putParcelableArrayListExtra(Site.JSON_ARRAY, sitesForMap);   //my new data
startActivityForResult(intent, this.ACCESS_GOOGLE);

This code is executed perfectly(sitesForMap and latLong are not null) but in the second Activity, when I try to instance the first Double[] parameter,
an error occured .

Bundle bundle = getIntent().getExtras();
double[] adresse = (double[]) bundle.getDoubleArray(Site.LATTITUDE);    //worked well until today
List<Site> sitesList = bundle.getParcelableArrayList(Site.JSON_ARRAY);

Error :

11-04 03:00:47.248: D/AndroidRuntime(642): Shutting down VM
11-04 03:00:47.248: W/dalvikvm(642): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-04 03:00:47.350: E/AndroidRuntime(642): FATAL EXCEPTION: main
11-04 03:00:47.350: E/AndroidRuntime(642): java.lang.OutOfMemoryError
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readArray(Parcel.java:1476)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readValue(Parcel.java:1810)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readListInternal(Parcel.java:2017)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readArrayList(Parcel.java:1461)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readValue(Parcel.java:1792)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Parcel.readMapInternal(Parcel.java:2008)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Bundle.unparcel(Bundle.java:208)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Bundle.getDoubleArray(Bundle.java:1431)
11-04 03:00:47.350: E/AndroidRuntime(642):  at alij.ne.jp.GoogleMapActivity.onCreate(GoogleMapActivity.java:111)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.os.Looper.loop(Looper.java:123)
11-04 03:00:47.350: E/AndroidRuntime(642):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-04 03:00:47.350: E/AndroidRuntime(642):  at java.lang.reflect.Method.invokeNative(Native Method)
11-04 03:00:47.350: E/AndroidRuntime(642):  at java.lang.reflect.Method.invoke(Method.java:521)
11-04 03:00:47.350: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-04 03:00:47.350: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-04 03:00:47.350: E/AndroidRuntime(642):  at dalvik.system.NativeStart.main(Native Method)
11-04 03:03:10.460: I/Process(642): Sending signal. PID: 642 SIG: 9
11-04 03:03:11.099: D/dalvikvm(652): GC_EXTERNAL_ALLOC freed 792 objects / 61464 bytes in 48ms

Someone knows what is the problem ?

Thank you for reading my message !

  • 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-05-26T15:55:22+00:00Added an answer on May 26, 2026 at 3:55 pm

    Your readFromParcel and writeToParcel methods doesn’t match.

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.site_name);
        dest.writeInt(this.category);
        dest.writeDouble(this.latitude);
        dest.writeDouble(this.longitude);
    }
    
    private void readFromParcel(Parcel in) {        
        this.id     = in.readInt();
        this.site_name  = in.readString();
        this.category   = in.readInt();
        this.latitude   = in.readInt(); // <-------- this
        this.longitude  = in.readInt(); // <-------- and this
    }
    

    A double uses 8 bytes, and an int uses 4 bytes on the parcel. A parcel doesn’t contain type information (except if you use writeValue and readValue), so if you mismatch the read and write methods, an unexpected value will be read and it will mess the whole parcel.

    If you really want an int, use (int) in.readDouble() instead of in.readInt().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have question about android spinner I have spinner which is populated by
Hello I have question about android spinner I have spinner which is populated by
I have question about removing element from QList. myclass.h: class node2D : public QObject
Have a question about sending data between classes and activities. I currently have a
I have question about the combo box. The problem I'm having is with the
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record

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.