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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:50:37+00:00 2026-06-08T03:50:37+00:00

< want to make a parcelable from an Object that contains an Arraylist, But

  • 0

< want to make a parcelable from an Object that contains an Arraylist, But in my readFromParcel method I get the error Type Mismatch: cannot convert from void to ArrayList. What can I do to read my ArrayList properly from my parcel?

edit: With the help of the answers below I now no longer get a type mismatch error, but now I get the message”- Syntax error on token “>”, invalid Name – Syntax error on token “>”, Expression expected after this token”

edit New errors were resolved when I cleaned the project.

Here’s my code

public class Game implements Parcelable{

private ArrayList<Stone> allStones;

public Game(){
    allStones = new ArrayList<Stone>();
    for(int x=0; x<10; x++) {
        for(int y=0; y<10; y++) {
            if((x+y)%2 == 1 && y<4){
                Stone stone = new Stone(x, y, Stone.WHITE);
                allStones.add(stone);
            } else if((x+y)%2 == 1 && y>5){
                Stone stone = new Stone(x, y, Stone.BLACK);
                allStones.add(stone);
            }
        }
    }
}

public Game(Parcel in) {
    allStones = new ArrayList<Stone>();
    readFromParcel(in);
}

public ArrayList<Stone> getAllStones() {
    return allStones;
}

public void removeFromStones(Stone stone) {
    allStones.remove(stone);
}

public int describeContents() {
    return 0;
}

public void writeToParcel(Parcel dest, int flags) {
    dest.writeTypedList(allStones);
}

private void readFromParcel(Parcel in) {
    in.readTypedList(allStones, Stone.CREATOR); //This line has the error in it
}
}

And the Stone class

public class Stone implements Parcelable{
private int x, y, color;
private Boolean king;

public static final int BLACK = 0;
public static final int WHITE = 1;

public Stone(int x, int y, int color) {
    this.x = x;
    this.y = y;
    this.color = color;
    this.king = false;
}

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

public int getX() {
    return x;
}

public int getY() {
    return y;
}

public int getColor() {
    return color;
}

public boolean getKing() {
    return king;
}

public void setKing() {
    king = true;
}

public void setXY(int x, int y) {
    this.x = x;
    this.y = y;
}

public int describeContents() {
    return 0;
}

public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(x);
    dest.writeInt(y);
    dest.writeInt(color);
    dest.writeByte((byte) (king ? 1:0));
}

public void readFromParcel(Parcel in) {
    x = in.readInt();
    y = in.readInt();
    color = in.readInt();
    king = in.readByte() == 1;
}

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

    public Stone createFromParcel(Parcel source) {
        return new Stone(source);
    }

    public Stone[] newArray(int size) {
        return new Stone[size];
    }
};
}
  • 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-08T03:50:39+00:00Added an answer on June 8, 2026 at 3:50 am

    readTypedList() does not return a value. It puts the list of objects into the list you pass as the first parameter. You code should look like this:

    private void readFromParcel(Parcel in) {
        in.readTypedList(allStones, Stone.CREATOR); // Should work now
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want make a xslt transformation to xsl-fo but I´m not really sure that
I want make validation jquery without using from plugin , problem is here that
I'm trying to make a Parcelable class that contains byte array. I have been
I want make a bash script which returns the position of an element from
I want make sql query which will insert values from one table to another
i want make a news site gets its content from other news sites, open
I want make the control height as double when the mouse is over that
I want to make a class serializable but i dont want make serializable some
I have a question: I want make a notification in status bar. But when
i want make function like that function(data){ } i want this data as this

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.