gpt4 book ai didi

java - firebase.database.DatabaseException : No properties to serialize found on class

转载 作者:行者123 更新时间:2023-11-30 04:57:20 25 4
gpt4 key购买 nike

我已经关注了一些具有相同上下文的问题,但我仍然没有找到理解或发现此错误的方法。我正在尝试将数据发送到我的 Firebase 实时数据库。付款的总费用,在我的购物车中列出和用户名,但我仍然收到此错误。

      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)

我的支付类

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;
}
}

我的 RequestDelivery 类

public class DeliveryRequest implements Serializable  {


public String firstNameProposer, lastNameProposer,address;

public DeliveryRequest() {


}
public String getFirstNameProposer() {
return firstNameProposer;
}

public void setFirstNameProposer(String firstNameProposer) {
this.firstNameProposer = firstNameProposer;
}

public String getLastNameProposer() {
return lastNameProposer;
}

public void setLastNameProposer(String lastNameProposer) {
this.lastNameProposer = lastNameProposer;
}
public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

最佳答案

我以前没有使用过 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;
... ... ...
}

请谷歌了解更多关于您应该为列表做什么的详细信息(代码中的提案详细信息)。我希望这有效。祝你好运。

关于java - firebase.database.DatabaseException : No properties to serialize found on class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58899548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com