com.google.firebase.database.DatabaseException: Serializing Arrays is not supported, please use Lists instead

前端 未结 7 532
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 19:57

I am trying to persist a custom object using the following code:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
Databas         


        
7条回答
  •  走了就别回头了
    2021-01-07 20:48

    //this will recreate your Object list by the constructor
    
    
    private void handleData(){ 
    
        orderList = Db.getCarts();
        orders = new ArrayList<>();
        Double totalPrice = 0.0;
    
        for (Order order : orderList){
            // totalPrice = totalPrice + ( price * quantity )
            totalPrice += (Double.valueOf(order.getPrice())* Integer.valueOf(order.getQuantity()));
            orders.add(new Order(order.getProductId(),order.getProductName(),order.getQuantity(),order.getPrice(),order.getDiscount(),order.getImage()));
        }
    }
    
     private void alertDialog() {
    
        AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
        alert.setTitle("One more step!");
        alert.setMessage("Enter your address");
    
        final EditText edtaddress = new EditText(getContext());
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT
        );
    
        edtaddress.setLayoutParams(layoutParams);
        alert.setView(edtaddress);
        alert.setIcon(R.drawable.ic_shopping_cart_black_24dp);
    
        alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Request request = new Request(
                        Common.currentUser.getPhone(),
                        Common.currentUser.getName(),
                        edtaddress.getText().toString(),
                        textTotal.getText().toString(),
                        orders
                );
    
                // Submit to firebase
                // We will using system.currentMillis to key
                requestReference.child(String.valueOf(System.currentTimeMillis()))
                        .setValue(request);
                //Delete cart
                Db.deleteCart();
                Toast.makeText(getContext(), "Thank you , Order Place", Toast.LENGTH_SHORT).show();
                getActivity().finish();
            }
        });
    
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    
        alert.show();
    
    }
    

提交回复
热议问题