我在我的项目中使用ORM Lite,我有一种情况,其中逐步引入了一个Person对象的意图,它有一个Collection of Email对象,但当我尝试读取这个类似LazyLoad的Collection时( 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):致命异乎寻常:主要 12-18 11:48:08.168:E / AndroidRuntime(26028): java.lang.RuntimeException:无法启动活动 ComponentInfo {com.example.pedidosexample / com.example.abertura.CadastroVisualizacao}: java.lang.IllegalStateException:内部DAO对象为null。懒 如果已经反序列化,则无法使用这些集合。 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):引起:java.lang.IllegalStateException: 内部DAO对象为null。如果它们不能使用惰性集合 已被反序列化。 12-18 11:48:08.168:E / AndroidRuntime(26028): 在 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并且与lite ORM一起使用?
谢谢!
答案 0 :(得分:-2)
@ForeignCollectionField(eager = true)