com.google.firebase.database.DatabaseException:无法将java.lang.String类型的值转换为布尔值

时间:2017-05-05 10:40:00

标签: android firebase

这是logcat。

  

E / UncaughtException:com.google.firebase.database.DatabaseException:   无法将java.lang.String类型的值转换为boolean                            在com.google.android.gms.internal.zzaix.zzaB(未知来源)                            在com.google.android.gms.internal.zzaix.zzc(未知来源)                            在com.google.android.gms.internal.zzaix.zzb(未知来源)                            在com.google.android.gms.internal.zzaix.zza(未知来源)                            在com.google.android.gms.internal.zzaix.zzb(未知来源)                            在com.google.android.gms.internal.zzaix $ zza.zze(未知来源)                            在com.google.android.gms.internal.zzaix $ zza.zzaC(未知来源)                            在com.google.android.gms.internal.zzaix.zzd(未知来源)                            在com.google.android.gms.internal.zzaix.zzb(未知来源)                            在com.google.android.gms.internal.zzaix.zza(未知来源)                            在com.google.firebase.database.DataSnapshot.getValue(未知来源)                            at com.talkativeparents.fragments.TPSoundingBoardFragment $ SBFireBasePrivateListAdapter $ 1.onChildChanged(TPSoundingBoardFragment.java:692)                            在com.google.android.gms.internal.zzaer.zza(未知来源)                            在com.google.android.gms.internal.zzagp.zzSu(未知来源)                            在com.google.android.gms.internal.zzags $ 1.run(未知来源)                            在android.os.Handler.handleCallback(Handler.java:815)                            在android.os.Handler.dispatchMessage(Handler.java:104)                            在android.os.Looper.loop(Looper.java:207)                            在android.app.ActivityThread.main(ActivityThread.java:5847)                            at java.lang.reflect.Method.invoke(Native Method)                            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

这是数据模型类变量及其类型:

public String channel_id;
public String doc_url;
public boolean is_parent_replied;
public boolean is_staff_replied;
public String message;
public String message_type;
public String posted_date;
public String posted_to;
public String school_with_class;
public String user_name;
public String uuid;

Firebase结构1

代码:

private void postMessage() {
    if (TPUtilities.checkNetworkConnection(this)) {
        if (!et_message.getText().toString().equals("")) {
            if (!et_to.getText().toString().equals("")) {


                if (!ed_subject.getText().toString().equals("")) {
                    if (et_message.length() <= 160) {

                        HashMap<String, Object> mComment1 = new HashMap<>();
                        mComment1.put("user_name", DUMMYSTRING);
                        mComment1.put("posted_to", TPUtilities.getCurrentDate());
                        //mComment1.put("message", "Welcome share your comments");
                        mComment1.put("doc_url", "");

                        ArrayList<HashMap> comentArray = new ArrayList<>();
                        for (int i = 0; i < 1; i++) {
                            comentArray.add(mComment1);
                        }

                        HashMap<String, Object> mLikeArray = new HashMap<>();
                        mLikeArray.put("user_name", DUMMYSTRING);
                        mLikeArray.put("posted_to", TPUtilities.getCurrentDate());


                        ArrayList<HashMap> likeArray = new ArrayList<>();
                        for (int i = 0; i < 1; i++) {
                            likeArray.add(mLikeArray);
                        }

                        HashMap<String, Object> mSelfLiked = new HashMap<>();
                        mSelfLiked.put("uuid", DUMMYSTRING);


                        ArrayList<HashMap> self = new ArrayList<>();
                        for (int i = 0; i < 1; i++) {
                            self.add(mSelfLiked);
                        }

                        // Create our 'model', a TPChatModelModel object
                        HashMap<String, Object> mPost = new HashMap<>();
                        mPost.put("id", TPApp.getInstance().getPrefs().getChildId());
                        System.out.println("\n Section:"+TPApp.getInstance().getPrefs().getClassName());
                        mPost.put("Section",TPApp.getInstance().getPrefs().getSectionName());
                        mPost.put("Class",TPApp.getInstance().getPrefs().getClassName());
                        mPost.put("actual_message", et_message.getText().toString());
                        System.out.println("Relation name:"+ TPApp.getInstance().getPrefs().getRelation() );
                        mPost.put("display_name", TPApp.getInstance().getPrefs().getRelation() + " of " + TPApp.getInstance().getPrefs().getChildName() + "-" + TPApp.getInstance().getPrefs().getSchoolListValue());
                        mPost.put("uuid", mUUID);
                        mPost.put("message_date", TPUtilities.getCurrentDate());
                        mPost.put("did_read", did_read);
                        mPost.put("is_parent_replied", is_parent_replied);
                        mPost.put("is_staff_replied", is_staff_replied);
                        if (isPrivate) {
                            if (TextUtils.isEmpty(et_sub_categoty.getText().toString())) {
                                mPost.put("posted_to", et_to.getText().toString());
                            } else {
                                mPost.put("posted_to", et_to.getText().toString() + "->" + et_sub_categoty.getText().toString());
                            }
                        } else {
                            mPost.put("posted_to", et_to.getText().toString() + "-" + ed_subject.getText().toString());
                        }
                        mPost.put("is_self_liked", self);
                        HashMap<String, Object> mLike = new HashMap<>();
                        mPost.put("likes", likeArray);
                        mPost.put("comments", comentArray);
                        mPost.put("subject", ed_subject.getText().toString());
                        mPost.put("doc_url", mUrlToSend);

                        if (isPrivate) {
                            mFireBaseRefPrivate.push().setValue(mPost, "null");
                        } else {
                            mFireBaseRefPublic.push().setValue(mPost, "null");
                        }

                        if (TPApp.getInstance().getPrefs().getPushSbPublic() != null) {
                            //// TODO: 5/23/2016  Notification to be resolved
                            if (isPrivate) {
                                sentNotification(et_message.getText().toString(), TPApp.getInstance().getPrefs().getPushSbPrivate(), mGetName, TPAppConstants.PUSH_SB_PRIVATE);
                            } else {
                                sentNotification(et_message.getText().toString(), TPApp.getInstance().getPrefs().getPushSbPublic(), mGetName, TPAppConstants.PUSH_SB);
                            }
                        }
                        et_message.setText("");
                        ed_subject.setText("");
                        mIsImageReady = false;
                        mUrlToSend = null;
                        showAlert(TPSBPostActivity.this,"Sounding Board","Thank You for contacting the school, You will receive a response "+responseStatus1);
                        /*
                        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(TPSBPostActivity.this);
                        myAlertDialog.setTitle("Sounding Board");
                        myAlertDialog.setMessage("Thank You for contacting the school, You will receive a response "+responseStatus);
                        myAlertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
                        {
                            public void onClick(DialogInterface arg0, int arg1)
                            {

                            }
                        });

                        myAlertDialog.show();
                        */
                        Toast.makeText(TPSBPostActivity.this, "Thank You for contacting the school, You will receive a response "+responseStatus1, Toast.LENGTH_SHORT).show();
                        finish();
                    } else {
                        Toast.makeText(TPSBPostActivity.this, getString(R.string.title_msg_long), Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(TPSBPostActivity.this, R.string.alert_subjectempty, Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(TPSBPostActivity.this, getString(R.string.title_to_empty), Toast.LENGTH_SHORT).show();
            }

        } else {
            Toast.makeText(TPSBPostActivity.this, getString(R.string.title_msg_empty), Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(TPSBPostActivity.this, getString(R.string.err_no_internet), Toast.LENGTH_SHORT).show();
    }
}

Onchildadded:

public void onChildChanged(DataSnapshot dataSnapshot, String s) {
    System.out.println("\n sounding board error on child added:"+dataSnapshot.getValue().toString());

    T model = dataSnapshot.getValue(SBFireBasePrivateListAdapter.this.mModelClass);
    //System.out.println("Model value:"+model.toString());
    String key = dataSnapshot.getKey();

    try {
        int index = mPrivateKeyArray.indexOf(key);
        mPrivateKeyArray.remove(index);
        mPrivateModel.remove(index);

        if (isMessageTop) {
            mPrivateModel.add(0, model);
            mPrivateKeyArray.add(0, key);
        } else {
            mPrivateModel.add(model);
            mPrivateKeyArray.add(key);
        }
    } catch (Exception e) {
        e.printStackTrace();
        //System.out.println("\n error from try catch inside SB on data change"+e.getLocalizedMessage() );
    }
    notifyDataSetChanged();
}

0 个答案:

没有答案