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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:31:29+00:00 2026-06-09T10:31:29+00:00

I am trying to implement a activity which takes a list of object and

  • 0

I am trying to implement a activity which takes a list of object and passing to another activty for processing. But I get NPE. This is my code.

public class Order implements Parcelable {

public static class OrderProduct {
    private String productId;
    private String qty;

    public OrderProduct(String productId, String qty) {
        this.productId = productId;
        this.qty = qty;
    }

    public String getProductId() {
        return productId;
    }

    public String getQty() {
        return qty;
    }

    public void setQty(String qty) {
        this.qty = qty;
    }

    @Override
    public String toString() {
        return "productId: " + productId + "  qty: " + qty;
    }   

}

private String  customerId;
private Map<String, OrderProduct> products;
private OrderProduct product;

public Order(String customerId) {
    this.customerId = customerId;
    products = new HashMap<String, OrderProduct>();
}

public Order(Parcel in)
{
    product.productId = in.readString();
    product.qty = in.readString();
}

public void setProduct(String productId, String qty) {
    product = products.get(productId);
    if (product == null) {
        product = new OrderProduct(productId, qty);
    }
    else {
        product.setQty(qty);
    }
    products.put(productId, product);
}

public Collection<OrderProduct> getProducts() {
    return products.values();
}

public String getCustomerId() {
    return customerId;
}

@Override
public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("Order: customerId: " + customerId + " { ");
    for (OrderProduct product : products.values()) {
        sb.append(" { ").append(product.toString()).append(" } ");
    }
    sb.append(" } ");
    return sb.toString();
}


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

@Override
public void writeToParcel(Parcel dest, int flags)
{
    // TODO Auto-generated method stub
    dest.writeString(product.getProductId());
    dest.writeString(product.qty);
}

public static final Order.Creator<Order> CREATOR = new Order.Creator<Order>() { 
    public Order createFromParcel(Parcel in) { 
        return new Order(in); 
    } 

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


}

############################# ACTIVITY 1 ##################

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.send_menu:
            //saveOrder(order);
            showOrderReview();
            break;
    }
    return true;
}  

############## ACITIVITY 2

public class ReviewOrderActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.main);

    Intent i = getIntent();
    Order myOrderObject = (Order) i.getParcelableExtra("order");
    Collection<Order.OrderProduct> products = myOrderObject.getProducts();
    System.out.println("Orderrrrrrrrrrrr : " + products.size());

    for (Order.OrderProduct product : products){
    Log.d("---", " product.getQty() "+product.getQty()+"  "+product.getProductId());        
}

}

  • 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-09T10:31:30+00:00Added an answer on June 9, 2026 at 10:31 am

    Without seeing your LogCat, this is the best that stands out:

    public Order(Parcel in) {
        product.productId = in.readString();
        product.qty = in.readString();
    }
    

    When this constructor is called, product is null. Additionally, in this constructor, products is not defined. Instead, do:

    public Order(Parcel in) {
        String productId = in.readString();
        String qty = in.readString();
        product = new OrderProduct(productId, qty);
        products = new HashMap<String, OrderProduct>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement an activity similar to InvokeWorkflow, which could dynamically load
I'm trying to implement multiple spinners within one activity, which appears to be working
This is the sample code for web services which am trying to implement .
I'm trying to implement ViewPager to combine two view within one activity, in which
I am trying to implement a WF4 activity extension which to handle some long
I am trying to implement an activity which shows a camera preview and contains
I am trying implement a search activity which gets data from a mysql table
I am trying to implement a layout, which contains a list of ViewPagers. Each
I am trying to implement the SVProgressHUD activity indicator. I copied the classes to
I am trying to implement the SVProgressHUD progress activity indicator. I copied the class

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.