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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:26:50+00:00 2026-06-15T17:26:50+00:00

I have an activity where I am adding objects into an ArrayList which implements

  • 0

I have an activity where I am adding objects into an ArrayList which implements the Parcelable interface. I then pass this list to another activity via a bundle however I get the following error when I try to print the size of the list in the new activity:

java.lang.RuntimeException: Unable to resume activity {com.example.test/com.example.test.SectionsActivity}: java.lang.NullPointerException

Here is the first activity where I add to list:

    @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Toast.makeText(getApplicationContext(), l.getItemAtPosition(position).toString() + " added to order", Toast.LENGTH_SHORT).show();
    // add clicked item to orderData....
    MenuItem m = (MenuItem) l.getItemAtPosition(position);
    // create new item
    orderData.add(m);
    subTotal += m.getPrice();
    calc();
}

This is first activity where I send the data via intent:

confirmBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            b.putParcelable("order", orderData);
            Intent i = new Intent(v.getContext(), SectionsActivity.class);
            i.putExtra("data",b);
            startActivity(i);

        }
    });

and this is second activity where I try to retrieve the bundle and display size:

@Override
protected void onResume() {
    super.onResume();
    getIntentData();
}


public void getIntentData(){
    Intent i = getIntent();
    if(i != null & i.hasExtra("data")){
        Toast.makeText(this.getApplicationContext(), "recieved", Toast.LENGTH_LONG).show();
        b = i.getExtras();
        orderData = b.getParcelable("order");
        int size = orderData.size();
        Toast.makeText(this.getApplicationContext(), String.valueOf(size), Toast.LENGTH_LONG).show();

    }
}

Any ideas why I am getting the null pointer?? It’s driving me mad!

orderData is a MenuItemList object:

public class MenuItemList extends ArrayList <MenuItem> implements Parcelable{

/**
 * 
 */
private static final long serialVersionUID = 2998684930374219271L;



public MenuItemList(){

}

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

    @Override
    public MenuItemList createFromParcel(Parcel source) {
        return new MenuItemList(source);
    }

    @Override
    public MenuItemList[] newArray(int size) {
        return new MenuItemList[size];
    }


};


public MenuItemList(Parcel source) {
        readFromParcel(source);
}

private void readFromParcel(Parcel source) {

    this.clear();

    //read the size of the list
    int size = source.readInt();

    //Remember order of items written into the Parcel. Important here.
    for(int i = 0; i < size; i ++){
        MenuItem item = new MenuItem();
        item.setName(source.readString());
        item.setPrice(source.readDouble());
        this.add(item);
    }
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    int size = this.size();

    dest.writeInt(size);

    for(int i = 0; i < size; i ++){
        MenuItem item = this.get(i);
        dest.writeString(item.getName());
        dest.writeDouble(item.getPrice());

    }

}

@Override
public int describeContents() {
    return 0;
}

}

CHANGES TO CODE THAT SOLVED PROBLEM:

CHANGED onClick(View v):

@Override
        public void onClick(View v) {
            Intent i = new Intent(v.getContext(), SectionsActivity.class);
            i.putExtra("data", (ArrayList<MenuItem>)orderData);
            startActivity(i);

        }

CHANGED getIntent():

public void getIntentData(){
    Intent i = getIntent();
    if(i != null && i.hasExtra("data")){
        Toast.makeText(this.getApplicationContext(), "recieved", Toast.LENGTH_LONG).show();
        orderData = i.getParcelableExtra("data");
        int size = orderData.size();
        Toast.makeText(this.getApplicationContext(), String.valueOf(size), Toast.LENGTH_LONG).show();

    }
}
  • 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-15T17:26:51+00:00Added an answer on June 15, 2026 at 5:26 pm

    Rewrite
    The problem is that you have an extra Bundle. Currently in getIntentData() you have to call:

    getIntent()                     // Fetch the Intent, 
        .getExtras()                // Fetch the Bundle of extras, 
        .getBundle("data")          // Fetch the Bundle "data", 
        .getParcelable("order");    // Then get your parcelable...  
    

    Let’s cut out the unnecessary Bundle.

    public void onClick(View v) {
        Intent i = new Intent(v.getContext(), SectionsActivity.class);
        i.putExtra("data", orderData);
        startActivity(i);
    }
    

    Now update getIntentData():

    Intent i = getIntent();
    if(i != null && i.hasExtra("data")){
        orderData = i.getParcelableExtra("data");
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity with a spinner which loads a simpleCursorAdaptor. I call another
I have a custom view which extends View. I am adding this to an
So basically, I have an Activity that implements an interface and has several inherited
I have an activity_A which contains listView, this listView dynamically increases in size adding
I am having trouble with my activity management. So I have activity A which
I have an activity with the following layout. So in this screen, initally the
I have implemented a custom list view which looks like the twitter timeline. adapter
I have an activity which contains only ScrollView and a TableLayout in it. In
Good day, I have an activity which i navigate to from an icon on
I have an activity in my app which displays rss feeds and next to

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.