Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法转换RealmList<;T>;到JSONObject字符串_Android_Realm - Fatal编程技术网

Android 无法转换RealmList<;T>;到JSONObject字符串

Android 无法转换RealmList<;T>;到JSONObject字符串,android,realm,Android,Realm,我有2个活动,我想在单击列表项时将数据从活动1发送到活动2。单击可以获得映射到该列表项的数据,该数据是一种RealmList类型。我使用Gson库将模型转换为Json字符串。如果我的数据是一种列表类型,但使用RealmList,我可以实现这一点。当我试图实现以下目标时,我的应用程序被冻结 这是我的过滤器型号: Filter filter = new Filter(); filter.setTitle(""); filter.setId(""); filter.se

我有2个活动,我想在单击列表项时将数据从活动1发送到活动2。单击可以获得映射到该列表项的数据,该数据是一种RealmList类型。我使用Gson库将模型转换为Json字符串。如果我的数据是一种列表类型,但使用RealmList,我可以实现这一点。当我试图实现以下目标时,我的应用程序被冻结

这是我的过滤器型号:

    Filter filter = new Filter();
    filter.setTitle("");
    filter.setId("");
    filter.setCode("");
RealmList类似于:

    RealmList<Filter> list = new RealmList<Filter>();
上面的live告诉我以下错误:

 PID: 12959 Reason: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago.  Wait queue length: 4.  Wait queue head age: 5647.8ms.)
                                            Load: 10.67 / 9.63 / 9.38
                                            CPU usage from 1103ms to -6084ms ago:
                                              101% 12959/com.anubavam.creatrix: 98% user + 3.4% kernel / faults: 6335 minor 15 major
                                              44% 832/system_server: 25% user + 18% kernel / faults: 8128 minor 104 major
                                              10% 1623/com.android.phone: 5.5% user + 5.4% kernel / faults: 4275 minor 57 major
                                              3.6% 4304/android.process.media: 1.7% user + 1.9% kernel / faults: 4931 minor 73 major
                                              0% 286/debuggerd: 0% user + 0% kernel / faults: 3205 minor 38 major
                                              5.8% 91/kswapd0: 0% user + 5.8% kernel
                                              5.8% 1272/com.android.systemui: 3.8% user + 1.9% kernel / faults: 2852 minor 39 major
                                              4.5% 302/zygote: 3% user + 1.5% kernel / faults: 11239 minor
                                              3.4% 1580/com.motorola.process.system: 2.3% user + 1.1% kernel / faults: 1881 minor 1 major
                                              3.3% 153/mmcqd/0: 0% user + 3.3% kernel
注意列表和ArrayList没有给我任何错误,它的工作文件。但RealmList是问题所在。 我也试着跟着这句话,但没用

    List<Filter> list = new RealmList<Filter>();
List List=newrealmlist();

任何人都可以解决这个问题。

到目前为止,领域对象不可
序列化,请参阅。这意味着您不能通过
Intent
将此对象传递给其他活动,也不能使用
GSON
库将其转换为
JSON

但是,有两种方法可以在第二个活动中使用模型

Intent intent = new Intent(this, OtherActvity.class);
intent.putExtra("itemId", listItem.getId());
startActivity(intent);
  • 通过
    Intent
    和第二个
    活动使用此键再次从DB获取模型
  • 可以使用此库序列化 对象并传递给第二个活动。 检查是否使用了打包机

  • 到目前为止,领域对象不可序列化,请参阅。这意味着您不能通过
    Intent
    将此对象传递给其他活动,也不能使用
    GSON
    库将其转换为
    JSON

    但是,有两种方法可以在第二个活动中使用模型

    Intent intent = new Intent(this, OtherActvity.class);
    intent.putExtra("itemId", listItem.getId());
    startActivity(intent);
    
  • 通过
    Intent
    和第二个
    活动使用此键再次从DB获取模型
  • 可以使用此库序列化 对象并传递给第二个活动。 检查是否使用了打包机

  • Realm当前不支持通过Intent传递数据。 可供选择的有

    1) 向第二个活动发送一些唯一Id,并在第二个活动上重新查询同一对象

    2) 也通过使用

    您可能还需要添加依赖项

    compile "org.parceler:parceler-api:x.x.x"
    apt "org.parceler:parceler:x.x.x"
    

    Realm当前不支持通过Intent传递数据。 可供选择的有

    1) 向第二个活动发送一些唯一Id,并在第二个活动上重新查询同一对象

    2) 也通过使用

    您可能还需要添加依赖项

    compile "org.parceler:parceler-api:x.x.x"
    apt "org.parceler:parceler:x.x.x"
    
    我想在单击列表项时将数据从活动1发送到活动2

    打包数据和创建数据的非托管/分离副本是对领域的滥用

    通过intent发送数据的主键,并在第二个活动中重新查询对象

    Intent intent = new Intent(this, OtherActvity.class);
    intent.putExtra("itemId", listItem.getId());
    startActivity(intent);
    

    我想在单击列表项时将数据从活动1发送到活动2

    打包数据和创建数据的非托管/分离副本是对领域的滥用

    通过intent发送数据的主键,并在第二个活动中重新查询对象

    Intent intent = new Intent(this, OtherActvity.class);
    intent.putExtra("itemId", listItem.getId());
    startActivity(intent);