我在相同的上下文中关注了一些问题,但仍无法理解或发现此错误。我正在尝试将数据发送到Firebase实时数据库。付款总费用,购物车中的清单和用户名,但仍然出现此错误。
.ToArray()
我的付款课程
com.google.firebase.database.DatabaseException: No properties to serialize found on class com.urbanx.urbaninsure.model.RequestDelivery
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@19.1.0:530)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@19.1.0:312)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.1.0:166)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-database@@19.1.0:60)
at com.google.firebase.database.DatabaseReference.setValueInternal(com.google.firebase:firebase-database@@19.1.0:282)
at com.google.firebase.database.DatabaseReference.setValue(com.google.firebase:firebase-database@@19.1.0:159)
at com.urbanx.urbaninsure.InsurancePayment$1.onClick(InsurancePayment.java:255)
我的RequestDelivery类
public class Payment extends AppCompatActivity implements View.OnClickListener {
LinearLayout InsurancePaymentLayout, MethodPaymentLayout, MpesaLayout, CreditCardLayout, EazzyPayLayout,
mpesaLayout, CreditBarLayout, EazzyPayBarLayout, PaymentStatementLayout,LAddress,
DeclinedPaymentStatementLayout,CompleteLayout, DeliveryLayout, hdCardLayout, cardLayout;
TextView tvCostStatement,tvCost, tvPay, tvAddress,etvAddress ;
TextView tvSerial, tvStroke, tvExpire, tvCardNumber;
RadioButton rbMpesa, rbCard, rbEazzy;
ProgressBar pbComplete;
Button bComplete, bDelivery, bPay;
ImageView ivMpesa, ivCredit;
EditText etCcn, etYear, etMonth, cd1, cd2, cd3, cd4;
List<ProposalDetails> cart = new ArrayList<>();
DatabaseHelper myDb;
CartAdapter adapter;
FirebaseDatabase database;
DatabaseReference requests;
CoordinatorLayout layout;
DatabaseReference mCustomerDatabase;
private FirebaseAuth mAuth;
private String totalPrice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insurance_payment);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
layout = (CoordinatorLayout)findViewById(R.id.layout);
LAddress = (LinearLayout)findViewById(R.id.LAddress);
etvAddress = (TextView) findViewById(R.id.etvAddress);
tvAddress = (TextView)findViewById(R.id.tvAddress);
bComplete = (Button)findViewById(R.id.bComplete);
bComplete.setOnClickListener(this);
cardLayout = (LinearLayout)findViewById(R.id.cardLayout);
cd1 = (EditText)findViewById(R.id.cd1);
cd2 = (EditText)findViewById(R.id.cd2);
cd3 = (EditText)findViewById(R.id.cd3);
cd4 = (EditText)findViewById(R.id.cd4);
ivCredit = (ImageView)findViewById(R.id.ivCredit);
hdCardLayout = (LinearLayout)findViewById(R.id.hdCardLayout);
tvCardNumber = (TextView)findViewById(R.id.tvCardNumber);
tvSerial = (TextView)findViewById(R.id.tvSerial);
tvStroke = (TextView)findViewById(R.id.tvStroke);
tvExpire =(TextView)findViewById(R.id.tvExpire);
etCcn = (EditText)findViewById(R.id.etCcn);
etMonth = (EditText)findViewById(R.id.etMonth);
etYear = (EditText)findViewById(R.id.etYear);
bPay = (Button)findViewById(R.id.bPay);
ivMpesa = (ImageView)findViewById(R.id.ivMpesa);
pbComplete = (ProgressBar)findViewById(R.id.pbComplete);
rbMpesa = (RadioButton)findViewById(R.id.rbMpesa);
rbMpesa.setOnClickListener(this);
rbCard = (RadioButton)findViewById(R.id.rbCard);
rbCard.setOnClickListener(this);
rbEazzy = (RadioButton)findViewById(R.id.rbEazzy);
rbEazzy.setOnClickListener(this);
tvCostStatement = (TextView)findViewById(R.id.tvCostStatement);
totalPrice = getIntent().getStringExtra("totalPrice");
tvCost = (TextView)findViewById(R.id.tvCost);
tvCost.setText(totalPrice);
tvCost.setText(totalPrice);
myDb = new DatabaseHelper(this);
adapter = new CartAdapter(cart,this);
database = FirebaseDatabase.getInstance();
requests = database.getReference("OrderRequests");
tvPay = (TextView)findViewById(R.id.tvPay);
InsurancePaymentLayout = (LinearLayout)findViewById(R.id.InsurancePaymentLayout);
MethodPaymentLayout = (LinearLayout)findViewById(R.id.MethodPaymentLayout);
MpesaLayout = (LinearLayout)findViewById(R.id.MpesaLayout);
CreditCardLayout = (LinearLayout)findViewById(R.id.CreditCardLayout);
EazzyPayLayout = (LinearLayout)findViewById(R.id.EazzyPayLayout);
mpesaLayout = (LinearLayout)findViewById(R.id.mpesaLayout);
mpesaLayout.setVisibility(View.GONE);
CreditBarLayout = (LinearLayout)findViewById(R.id.CreditBarLayout);
CreditBarLayout.setVisibility(View.GONE);
EazzyPayBarLayout = (LinearLayout)findViewById(R.id.EazzyPayBarLayout);
EazzyPayBarLayout.setVisibility(View.GONE);
PaymentStatementLayout = (LinearLayout)findViewById(R.id.PaymentStatementLayout);
PaymentStatementLayout.setVisibility(View.GONE);
DeclinedPaymentStatementLayout = (LinearLayout)findViewById(R.id.DeclinedPaymentStatementLayout);
CompleteLayout = (LinearLayout)findViewById(R.id.CompleteLayout);
CompleteLayout.setVisibility(View.VISIBLE);
DeliveryLayout = (LinearLayout)findViewById(R.id.DeliveryLayout);
bDelivery = (Button)findViewById(R.id.bDelivery);
bDelivery.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.rbMpesa:
if (rbMpesa.isChecked()){
rbCard.setChecked(false);
rbEazzy.setChecked(false);
mpesaLayout.setVisibility(View.VISIBLE);
CreditBarLayout.setVisibility(View.GONE);
EazzyPayBarLayout.setVisibility(View.GONE);
}
break;
case R.id.rbCard:
if (rbCard.isChecked()){
rbMpesa.setChecked(false);
rbEazzy.setChecked(false);
mpesaLayout.setVisibility(View.GONE);
CreditBarLayout.setVisibility(View.VISIBLE);
EazzyPayBarLayout.setVisibility(View.GONE);
}
break;
case R.id.rbEazzy:
if (rbEazzy.isChecked()){
rbMpesa.setChecked(false);
rbCard.setChecked(false);
mpesaLayout.setVisibility(View.GONE);
CreditBarLayout.setVisibility(View.GONE);
EazzyPayBarLayout.setVisibility(View.VISIBLE);
}
break;
case R.id.bComplete:
showAlertDialog();
break;
case R.id.bDelivery:
startActivity(new Intent(this, DeliveryActivity.class));
break;
}
}
private void showAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Final step!");
alertDialog.setMessage("Enter your delivery location: ");
LayoutInflater inflater = LayoutInflater.from(this);
View destination_layout = inflater.inflate(R.layout.enter_address,null);
final EditText etAddress = destination_layout.findViewById(R.id.edtAddress);
alertDialog.setView(destination_layout);
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final android.app.AlertDialog waitingDialog = new SpotsDialog(InsurancePayment.this,"Placing ");
waitingDialog.show();
if (TextUtils.isEmpty(etAddress.getText().toString()))
{
Snackbar.make(layout,"Please enter delivery location", Snackbar.LENGTH_SHORT)
.show();
return;
}
String address = etAddress.getText().toString();
DeliveryRequest requestDelivery = new DeliveryRequest();
requestDelivery.setFirstNameProposer("am");
requestDelivery.setLastNameProposer("");
requestDelivery.setAddress("address");
// String json = gson.toJson(requestDelivery);
String requestId = requests.push().getKey();
requests.child(requestId)
.setValue(requestDelivery);
myDb.deleteAllInsurance();
myDb.deleteAllInsurance();
LAddress.setVisibility(View.VISIBLE);
etvAddress.setText(address);
waitingDialog.dismiss();
Toast.makeText(InsurancePayment.this,"Thank your, Order placed",Toast.LENGTH_SHORT).show();
PaymentStatementLayout.setVisibility(View.VISIBLE);
CompleteLayout.setVisibility(View.GONE);
pbComplete.setVisibility(View.VISIBLE);
DeliveryLayout.setVisibility(View.VISIBLE);
}
});
alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
}
});
alertDialog.show();
}
@Override
public void onBackPressed() {
if ((pbComplete.getVisibility() == View.VISIBLE)&&(DeliveryLayout.getVisibility()==View.VISIBLE)) {
// Its visible
} else {
Intent openProposalForm = new Intent(InsurancePayment.this, Cart.class);
startActivity(openProposalForm);
finish();
// Either gone or invisible
}
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
}
}
答案 0 :(得分:0)
我以前没有使用过Firebase数据库,但是我使用了其他可以提供JSON响应的API,或者将JSON响应发送到服务器。因此,当您获取/发送JSON响应时,您需要告诉Java如何使用@SerializedName
来读取它。
因此,例如,如果您收到这样的json响应:
{
phone:"12345678",
__total:"1000",
... ...
}
我认为在这种情况下,您需要像这样对RequestDelivery
类进行更改:
class RequestDelivery{
@SerializedName("phone") /* here this 'phone' is the string that is exactly in the json response*/
public String phone;
@SerializedName("__total") /* put __total because it is in my sample json. You change it according to your actual json response */
public String total;
... ... ...
}
请Google进一步了解您应如何处理列表(代码中的proposalDetails)。 我希望这行得通。祝你好运。