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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:13+00:00 2026-06-13T07:18:13+00:00

I am running into an issue where instantiating an Object from a Parcel is

  • 0

I am running into an issue where instantiating an Object from a Parcel is throwing a NullPointerException. My Class Contact implements Parcelable, contains a CREATOR, and all the hookups seem to work. A Contact object represents a contact in an Address book. The variables used are of types:

String firstName, lastName, note;
List<String> emails, phones;

The constructor initializes all the strings to “” and all the lists to empty lists. The writeToParcel and Contact(Parcel in) methods are shown below:

public void writeToParcel(Parcel out, int flags) {
    out.writeString(firstName);
    out.writeString(lastName);

    //If there are emails, write a 1 followed by the list. Otherwise, write a 0
    if (!emails.isEmpty())
    {
        out.writeInt(1);
        out.writeStringList(emails);
    }
    else
        out.writeInt(0);

    //If there are phone numbers, write a 1 followed by the list. Otherwise, write a 0
    if (!phones.isEmpty())
    {
        out.writeInt(1);
        out.writeStringList(phones);
    }
    else
        out.writeInt(0);
    out.writeString(note);
}

…

public Contact(Parcel in)
{
    firstName = in.readString();
    Log.i(TAG, firstName);
    lastName = in.readString();
    Log.i(TAG, lastName);
    int emailsExist = in.readInt();
    if (emailsExist == 1)
        in.readStringList(emails);
    else
        emails = new ArrayList<String>();
    int phonesExist = in.readInt();
    if (phonesExist == 1)
        in.readStringList(phones);//Line 80, where this app breaks
    else
        phones = new ArrayList<String>();
    note = in.readString();
}

The test I am currently working on provides a valid first and last name, one phone number, and a note. The relevant output I get when upacking this parcelable is as follows:

FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo...
...
Caused by: java.lang.NullPointerException
    at android.os.Parcel.readStringList(Parcel.java:1718)
    at com.mycompany.android.Contact.<init>(Contact.java:80) //This is the line marked above
    at com.mycompany.android.Contact$1.createFromParcel(Contact.java:40) //This is inside the CREATOR
    ...

What am I doing incorrectly? Can numbers not be written as String lists, or did I do something incorrectly?

  • 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-13T07:18:14+00:00Added an answer on June 13, 2026 at 7:18 am

    I just poked around a few minutes more, and realized my mistake. The readStringList method cannot receive a null argument. My new Contact(Parcel in) method is as follows:

    public Contact(Parcel in)
    {
        firstName = in.readString();
        Log.i(TAG, firstName);
        lastName = in.readString();
        Log.i(TAG, lastName);
        int emailsExist = in.readInt();
        emails = new ArrayList<String>();
        if (emailsExist == 1)
            in.readStringList(emails);
        int phonesExist = in.readInt();
        phones = new ArrayList<String>();
        if (phonesExist == 1)
            in.readStringList(phones);          
        note = in.readString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into an issue trying to create delegates from MethodInfo .
I'm running into an issue that's arising from the fact that one has to
I'm running into an issue where my deployment loops through Recycling. From Visual Studio:
I'm using C# and WebForms and running into an issue. I have a class
I keep running into this issue: class CCreateShortcutTask : public CTask { public: CCreateShortcutTask(
I am running into an issue with running javascript from an external javascript file
I am currently running into an issue of calling an Win32 DLL[Native] from a
I am currently running into an issue when attempting to pull contacts from a
I'm running into an issue calling a User Defined Function from a LINQ query.
I am running into this issue of releasing an already released object but can't

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.