首页 > 解决方案 > 运行时应用程序崩溃并且不提供代码路径

问题描述

在此处输入图像描述当我运行应用程序时,它在昨天运行时在开始屏幕中崩溃,我没有更改代码中的任何内容,我编写了相同的代码并且它成功运行,所以我不认为这不是代码中的错误,当我查看 logcat 它给出的错误没有错误的代码路径

2019-07-10 11:28:31.185 28663-28663/com.best.karem.mycareassociatesadmin E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.best.karem.mycareassociatesadmin, PID: 28663
com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long
    at com.google.android.gms.internal.zzelw.zzb(Unknown Source:616)
    at com.google.android.gms.internal.zzelw.zza(Unknown Source:301)
    at com.google.android.gms.internal.zzelw.zzb(Unknown Source:0)
    at com.google.android.gms.internal.zzelx.zze(Unknown Source:71)
    at com.google.android.gms.internal.zzelw.zzb(Unknown Source:146)
    at com.google.android.gms.internal.zzelw.zza(Unknown Source:0)
    at com.google.firebase.database.DataSnapshot.getValue(Unknown Source:10)
    at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151)
    at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:140)
    at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:183)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
    at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
    at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1888)
    at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
    at android.view.Choreographer.doCallbacks(Choreographer.java:893)
    at android.view.Choreographer.doFrame(Choreographer.java:809)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
    at android.os.Handler.handleCallback(Handler.java:907)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7593)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

笔记

这些代码片段的链接都不在我的课堂上,所以我无法更改其中的任何一个

Model class

public class Lead {

private String name;
private String contactPhone;
private String amount;
private String info;
private String purpose;
private String status;
private long actionDate;
private String nextActionDate;
private String sanctionedPayment;
private String paid;
private String userId;



public Lead() {

}

public Lead(String name, String contactPhone, String amount, String info, String purpose, String status, long actionDate, String nextActionDate, String sanctionedPayment , String paid , String userId) {
    this.name = name;
    this.contactPhone = contactPhone;
    this.amount = amount;
    this.info = info;
    this.purpose = purpose;
    this.status = status;
    this.actionDate = actionDate;
    this.nextActionDate = nextActionDate;
    this.sanctionedPayment = sanctionedPayment;
    this.paid = paid;
    this.userId = userId;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getPaid() {
    return paid;
}

public void setPaid(String paid) {
    this.paid = paid;
}

public long getActionDate() {
    return actionDate;
}

public void setActionDate(long actionDate) {
    this.actionDate = actionDate;
}

public String getNextActionDate() {
    return nextActionDate;
}

public void setNextActionDate(String nextActionDate) {
    this.nextActionDate = nextActionDate;
}

public String getSanctionedPayment() {
    return sanctionedPayment;
}

public void setSanctionedPayment(String sanctionedPayment) {
    this.sanctionedPayment = sanctionedPayment;
}

public String getStatus() {
    return status;
}


public void setStatus(String status) {
    this.status = status;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getContactPhone() {
    return contactPhone;
}

public void setContactPhone(String contactPhone) {
    this.contactPhone = contactPhone;
}

public String getAmount() {
    return amount;
}

public void setAmount(String amount) {
    this.amount = amount;
}

public String getInfo() {
    return info;
}

public void setInfo(String info) {
    this.info = info;
}

public String getPurpose() {
    return purpose;
}

public void setPurpose(String purpose) {
    this.purpose = purpose;
}

}

public class EditLeadActivity extends AppCompatActivity {

private DatabaseReference leadRef;


private TextView leadName, leadContactPhone, leadAmount, leadInfo, leadPurpose, leadStatus, leadActionDate, leadNextActionDate, leadPaymentSanctioned , leadPaymentPiad;


private String key = "";

private Lead leadModel;

private String name;
private String contactPhone;
private String amount;
private String info;
private String purpose;
private String status;
private long actionDate;
private String nextActionDate;
private String paymentSanctioned;
private String paid;
private String special = "";
private boolean isClicked = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_lead);

    leadRef = FirebaseDatabase.getInstance().getReference().child("Leads");
    leadRef.keepSynced(true);

    Intent intent = getIntent();
    key = intent.getStringExtra("leadId");




    leadName = findViewById(R.id.edit_lead_name);
    leadContactPhone = findViewById(R.id.edit_lead_contact_phone);
    leadAmount = findViewById(R.id.edit_lead_amount);
    leadInfo = findViewById(R.id.edit_lead_info);
    leadPurpose = findViewById(R.id.edit_lead_purpose);
    leadStatus = findViewById(R.id.edit_lead_status);
    leadActionDate = findViewById(R.id.edit_lead_action_date);
    leadNextActionDate = findViewById(R.id.edit_lead_next_action_date);
    leadPaymentSanctioned = findViewById(R.id.edit_lead_payment_sanctioned);
    leadPaymentPiad = findViewById(R.id.edit_lead_paid_status);
    leadPaymentPiad.setTextColor(Color.parseColor("#e10404"));



    if(intent.hasExtra("special"))
        leadPaymentPiad.setVisibility(View.VISIBLE);



    leadRef.child(key).addValueEventListener(new 
    ValueEventListener() {
        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            leadModel = dataSnapshot.getValue(Lead.class);

            name = leadModel.getName();
            contactPhone = leadModel.getContactPhone();
            amount = leadModel.getAmount();
            info = leadModel.getInfo();
            purpose = leadModel.getPurpose();
            status = leadModel.getStatus();
            actionDate = leadModel.getActionDate();
            nextActionDate = leadModel.getNextActionDate();
            paymentSanctioned = leadModel.getSanctionedPayment();
            paid = leadModel.getPaid();



            leadName.setText("Name: " + name);
            leadContactPhone.setText("Contact Phone: " + contactPhone);
            leadAmount.setText("Amount: " + amount);
            leadInfo.setText("Information: " + info);
            leadPurpose.setText("Purpose: " + purpose);
            leadStatus.setText("Status: " + status);
            leadActionDate.setText("Action Date: " + getDate(actionDate));
            leadNextActionDate.setText("Next Action Date: " + nextActionDate);
            leadPaymentSanctioned.setText("Payment Sanctioned: " + paymentSanctioned );
            leadPaymentPiad.setText("Paid: " + paid);

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    leadPaymentPiad.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


             if(!isClicked){

                 leadPaymentPiad.setTextColor(Color.parseColor("#00CC2C"));
                 leadPaymentPiad.setText("Paid: " + "yes");
                 leadRef.child(key).child("paid").setValue("yes").addOnCompleteListener(new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {

                         if(task.isSuccessful()){
                             Toast.makeText(EditLeadActivity.this, "Changed to Yes", Toast.LENGTH_SHORT).show();
                         }else {
                             Toast.makeText(EditLeadActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                         }

                     }
                 });

                isClicked = true;
            }else if(isClicked) {

                 leadPaymentPiad.setTextColor(Color.parseColor("#e10404"));
                 leadPaymentPiad.setText("Paid: " + "no");

                 leadRef.child(key).child("paid").setValue("no").addOnCompleteListener(new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {

                         if(task.isSuccessful()){
                             Toast.makeText(EditLeadActivity.this, "Changed to No", Toast.LENGTH_SHORT).show();
                         }else {
                             Toast.makeText(EditLeadActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                         }

                     }
                 });

                 isClicked = false;
             }

        }
    });

    leadActionDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent editFieldIntent = new Intent(EditLeadActivity.this , EditLeadField.class);
            editFieldIntent.putExtra("id" , "1");
            editFieldIntent.putExtra("leadId" , key);
            startActivity(editFieldIntent);

        }
    });

    leadNextActionDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent editFieldIntent = new Intent(EditLeadActivity.this , EditLeadField.class);
            editFieldIntent.putExtra("id" , "2");
            editFieldIntent.putExtra("leadId" , key);
            startActivity(editFieldIntent);

        }
    });

    leadPaymentSanctioned.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent editFieldIntent = new Intent(EditLeadActivity.this , EditLeadField.class);
            editFieldIntent.putExtra("id" , "3");
            editFieldIntent.putExtra("leadId" , key);
            startActivity(editFieldIntent);

        }
    });

    leadStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent changeStatusIntent = new Intent(EditLeadActivity.this , ChangeStatus.class);
            changeStatusIntent.putExtra("leadId",  key);
            startActivity(changeStatusIntent);

        }
    });

}

private String getDate(long actionDate) {

    SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yyyy 
    HH:mm:ss");

    return sfd.format(new Date(actionDate));

}

}

标签: androidfirebase

解决方案


推荐阅读