gpt4 book ai didi

android - 如果已反序列化,则不能使用惰性集合

转载 作者:太空狗 更新时间:2023-10-29 15:28:21 26 4
gpt4 key购买 nike

我在我的项目中使用 ORM Lite,我有这样一种情况,即 putExtra Person 对象的 Intent ,它有一个 Email 对象集合,但是当我尝试读取这个集合时,它就像 LazyLoad ( eager = false) 下面遵循用于检索电子邮件集合的模型和代码:

public class Pessoa implements Serializable{

@DatabaseField(generatedId=true)
private int id;

...

@ForeignCollectionField(eager=false)
private Collection<Email> emails;

...
}
public class Email implements Serializable{

@DatabaseField(generatedId=true)
private int id;

...

@DatabaseField(foreign=true)
private Pessoa pessoa;

...
}

检索集合:

if(getIntent().hasExtra("Pessoa")){
pessoa = (Pessoa) getIntent().getSerializableExtra("Pessoa");

Iterator<Endereco> iterator = pessoa.getEnderecos().iterator();
while(iterator.hasNext()){
Endereco end = iterator.next();
Log.e("ENDERECO",end.getLogradouro());
}

我收到以下错误:

12-18 11:48:08.168: E/AndroidRuntime(26028): FATAL EXCEPTION: main 12-18 11:48:08.168: E/AndroidRuntime(26028): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pedidosexample/com.example.abertura.CadastroVisualizacao}: java.lang.IllegalStateException: Internal DAO object is null. Lazy collections cannot be used if they have been deserialized. 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread.access$600(ActivityThread.java:128) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.os.Handler.dispatchMessage(Handler.java:99) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.os.Looper.loop(Looper.java:137) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread.main(ActivityThread.java:4517) 12-18 11:48:08.168: E/AndroidRuntime(26028): at java.lang.reflect.Method.invokeNative(Native Method) 12-18 11:48:08.168: E/AndroidRuntime(26028): at java.lang.reflect.Method.invoke(Method.java:511) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) 12-18 11:48:08.168: E/AndroidRuntime(26028): at dalvik.system.NativeStart.main(Native Method) 12-18 11:48:08.168: E/AndroidRuntime(26028): Caused by: java.lang.IllegalStateException: Internal DAO object is null. Lazy collections cannot be used if they have been deserialized. 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java:310) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java:71) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java:60) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:47) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:28) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.example.abertura.CadastroVisualizacao.preencheCampos(CadastroVisualizacao.java:85) 12-18 11:48:08.168: E/AndroidRuntime(26028): at com.example.abertura.CadastroVisualizacao.onCreate(CadastroVisualizacao.java:53) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.Activity.performCreate(Activity.java:4470) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053) 12-18 11:48:08.168: E/AndroidRuntime(26028): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934) 12-18 11:48:08.168: E/AndroidRuntime(26028): ... 11 more

错误清楚地说明了问题所在,但它有另一种方法将 Person 对象传递给另一个 Intent ,并且适用于精简版 ORM?

谢谢!

最佳答案

@ForeignCollectionField(eager = true)

关于android - 如果已反序列化,则不能使用惰性集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20659985/

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