ORMLite : Internal DAO object is null

后端 未结 2 358
不知归路
不知归路 2021-01-14 03:15

I\'m using ORMLite, trying to use the ForeignCollectionKey but I got the following error :

Internal DAO object is null. LazyCollections cannot be use

2条回答
  •  既然无缘
    2021-01-14 04:15

    I solved this problem like Gray suggested: pass the primary key attribute in the Bundle and then obtain the object again from the database in the destination Activity:

    Example:

    Let's suppose I want to pass a Person object and that I've declared Person.name as:

    @DatabaseField (columnName ="name")
    private String name;
    

    Then:

    ActivityA

    Intent intent = new Intent(ActivityA.this, ActivityB.class);
    Bundle bundle = new Bundle();
    bundle.putString("NAME" Person.getName());
    intent.putExtras(bundle);
    

    ActivityB

    String name = getIntent().getExtras().getString("NAME"));
    Person p = getHelper().getPersonDao().queryForEq("name", name);
    

    And there you are, your Collection will be refreshed.

提交回复
热议问题