本文介绍了如何传递数组列表<Object>到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将数组列表传递给意图,但出现错误.所以请告诉我出了什么问题.这是我的代码
I pass Array list to intent but give an error . so please tell me what is wrong.This is my code
用于发送
addToCartList=new ArrayList<>();
Intent intent=new Intent(ShopingCart.this,SelectedProductFromShopingCartShow.class);
intent.putExtra("selectedList", (Serializable) addToCartList);
startActivity(intent);
这是我的接收器代码
public class SelectedProductFromShopingCartShow extends AppCompatActivity{
ArrayList<ShowProducts> arrayList=new ArrayList<>();
String condition="SelectedItemsFromShoppingCart";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_product_from_shoping_cart_show);
arrayList= (ArrayList<ShowProducts>) getIntent().getSerializableExtra("selectedList");
}
}
这是我的错误
07-25 20:15:54.280 16503-16503/com.sizdom.sizdomstockmanager E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Parcel: unable to marshal value ShowProducts{product_name='Almost new', product_photo='http://192.168.1.39:81/sizdom/sizdomstock/product_images/1-Almost-new-17-07-11-10-27-21.jpg', product_sizes=0, product_created_date='null'}
at android.os.Parcel.writeValue(Parcel.java:1235)
at android.os.Parcel.writeList(Parcel.java:622)
at android.os.Parcel.writeValue(Parcel.java:1195)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6660)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1865)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3331)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:3566)
at android.app.Activity.startActivity(Activity.java:3534)
at com.sizdom.sizdomstockmanager.ShopingCart$1.onClick(ShopingCart.java:66)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5069)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
07-25 20:20:54.325 700-910/system_process E/InputDispatcher: channel '536cf278 com.sizdom.sizdomstockmanager/com.sizdom.sizdomstockmanager.SplashScrean (server)' ~ Channel is unrecoverably broken and will be disposed!
07-25 20:20:54.325 700-910/system_process E/InputDispatcher: channel '535f9848 com.sizdom.sizdomstockmanager/com.sizdom.sizdomstockmanager.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-25 20:20:54.381 21855-21855/? E/Trace: error opening trace file: No such file or directory (2)
07-25 20:20:54.557 21855-21855/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
ShowProducts 类
ShowProducts class
public class ShowProducts {
String product_name;
String product_photo;
int product_sizes;
String product_created_date;
int size_id;
String size_name;
int size_price;
int size_cost;
int size_quantity;
int product_id;
public int getProduct_id() {
return product_id;
}
public void setProduct_id(int product_id) {
this.product_id = product_id;
}
public String getProduct_name() {
return product_name;
}
public void setProduct_name(String product_name) {
this.product_name = product_name;
}
public String getProduct_photo() {
return product_photo;
}
public void setProduct_photo(String product_photo) {
this.product_photo = product_photo;
}
public int getProduct_sizes() {
return product_sizes;
}
public void setProduct_sizes(int product_sizes) {
this.product_sizes = product_sizes;
}
public String getProduct_created_date() {
return product_created_date;
}
public void setProduct_created_date(String product_created_date) {
this.product_created_date = product_created_date;
}
public int getSize_id() {
return size_id;
}
public void setSize_id(int size_id) {
this.size_id = size_id;
}
public String getSize_name() {
return size_name;
}
public void setSize_name(String size_name) {
this.size_name = size_name;
}
public int getSize_price() {
return size_price;
}
public void setSize_price(int size_price) {
this.size_price = size_price;
}
public int getSize_cost() {
return size_cost;
}
public void setSize_cost(int size_cost) {
this.size_cost = size_cost;
}
public int getSize_quantity() {
return size_quantity;
}
public void setSize_quantity(int size_quantity) {
this.size_quantity = size_quantity;
}
}
推荐答案
请在您的模型类中编写ShowProducts implements Serializable
.
这将解决问题.
Please write ShowProducts implements Serializable
in your model class.
This will resolve the issue.
这篇关于如何传递数组列表<Object>到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!