自4月15日以来,我在Quickblox中遇到问题,当时Quickblox将适用于Android的SDK更新为2.5.2。
我注意到的问题是,如果我为对话框填充了customData参数,那么它将引发下面提到的IOExeption。否则没有问题。

不会出现任何问题的对话框。


  QBDialog {id = xxxx,created_at = 2016-19-04 11:36:54,
  last_msg_user_id = xxxx,occupants_ids = [xxxx,xxxx,last_message =嘿,
  last_message_date_sent = 1461046124,类型= PRIVATE,名称= xxxx,
  room_jid = null,user_id = xxxx,photo = null,unread_message_count = 0,
  customData = null}


导致崩溃的对话框。


  QBDialog {id = xxxx,created_at = 2016-19-04 12:01:00,
  last_msg_user_id = xxxx,occupants_ids = [xxxx,xxxx],last_message =你好,
  last_message_date_sent = 1461047494,类型= PRIVATE,名称= xxxx,
  room_jid = null,user_id = xxxx,photo = null,unread_message_count = 1,
  customData = QBBaseCustomObject {className ='DialogueRelationState',
  字段= {isFriends = true,location_field =空}}}


将上述对话框传递给Activity_chat类的代码段

Bundle bundle = new Bundle();
bundle.getString(selectedDialog.toString());
bundle.putSerializable(Activity_Chat.EXTRA_DIALOG, selectedDialog);
Activity_Chat.start(DrawActivity_Chatlist.this, bundle);// error points here


接收活动的启动方法

public static void start(Context context, Bundle bundle) {

    Intent intent = new Intent(context, Activity_Chat.class);
    intent.putExtras(bundle);
    context.startActivity(intent); //error points here
}


错误日志:

Fatal Exception: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.quickblox.chat.model.QBDialog)
       at android.os.Parcel.writeSerializable(Parcel.java:1323)
       at android.os.Parcel.writeValue(Parcel.java:1271)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
       at android.os.Bundle.writeToParcel(Bundle.java:1692)
       at android.os.Parcel.writeBundle(Parcel.java:643)
       at android.content.Intent.writeToParcel(Intent.java:7152)
       at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2663)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
       at android.app.Activity.startActivityForResult(Activity.java:3532)
       at android.app.Activity.startActivityForResult(Activity.java:3458)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
       at android.app.Activity.startActivity(Activity.java:3780)
       at android.app.Activity.startActivity(Activity.java:3748)
       at com.social.fitspur.activities.Activity_Chat.start(Activity_Chat.java:100)
       at com.social.fitspur.activities.DrawActivity_Chatlist$3.onItemClick(DrawActivity_Chatlist.java:198)
       at android.widget.AdapterView.performItemClick(AdapterView.java:299)
       at android.widget.AbsListView.performItemClick(AbsListView.java:1162)
       at android.widget.AbsListView$PerformClick.run(AbsListView.java:2953)
       at android.widget.AbsListView$3.run(AbsListView.java:3708)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:5257)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.io.NotSerializableException: org.json.JSONObject$1
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
       at java.util.HashMap.writeObject(HashMap.java:995)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1055)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
       at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
       at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
       at android.os.Parcel.writeSerializable(Parcel.java:1318)
       at android.os.Parcel.writeValue(Parcel.java:1271)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
       at android.os.Bundle.writeToParcel(Bundle.java:1692)
       at android.os.Parcel.writeBundle(Parcel.java:643)
       at android.content.Intent.writeToParcel(Intent.java:7152)
       at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2663)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
       at android.app.Activity.startActivityForResult(Activity.java:3532)
       at android.app.Activity.startActivityForResult(Activity.java:3458)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
       at android.app.Activity.startActivity(Activity.java:3780)
       at android.app.Activity.startActivity(Activity.java:3748)
       at com.social.fitspur.activities.Activity_Chat.start(Activity_Chat.java:100)
       at com.social.fitspur.activities.DrawActivity_Chatlist$3.onItemClick(DrawActivity_Chatlist.java:198)
       at android.widget.AdapterView.performItemClick(AdapterView.java:299)
       at android.widget.AbsListView.performItemClick(AbsListView.java:1162)
       at android.widget.AbsListView$PerformClick.run(AbsListView.java:2953)
       at android.widget.AbsListView$3.run(AbsListView.java:3708)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:5257)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
       at dalvik.system.NativeStart.main(NativeStart.java)


我从中了解到的是,它在Dialog中遇到无法序列化的JSON形式的错误。

注意:在4月15日之前,它运行良好,并且我也没有对自定义类进行任何更改

我尝试将SDK版本从v2.5升级到v2.5.2,但是没有用。

最佳答案

QuickBlox最近添加了一个location_field,它返回jsonObject但需要字符串。最后,在获取对话框的同时添加此行即可达到目的。

for (QBDialog dialog : dialogs) {
    QBDialogCustomData customData = dialog.getCustomData();
    usersIDs.addAll(dialog.getOccupants());
    if (customData == null) {
        continue;
    }
    HashMap<String, Object> fields = customData.getFields();
    if (!fields.isEmpty()) {
        fields.put("location_field", null);
    }
}

关于android - 可打包遇到IOException,正在编写可序列化对象[QUICKBLOX DIALOG],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36834145/

10-13 04:08