gpt4 book ai didi

android - ActiveAndroid 模型包附加异常

转载 作者:行者123 更新时间:2023-11-29 00:29:56 26 4
gpt4 key购买 nike

伙计们!我写了一个 Book 类,它有 Chapter 对象(一对多关系)。它实现了方法 public List chapters(),如文档中所述。这是 Book.java

@Table(name = "Books")
public class Book extends Model implements Serializable {

private static final long serialVersionUID = 1L;

@Column(name = "Name", unique = true, onUniqueConflict = Column.ConflictAction.IGNORE)
public String name;

@Column(name = "Sort")
public int sort;

public Book() {
super();
}

public Book(String name, int sort) {
super();
this.name = name;
this.sort = sort;
}

public List<Chapter> chapters() {
return getMany(Chapter.class, "Book");
}

@Override
public String toString() {
return name;
}
}

在主要 Activity 中,我可以成功获取 Chapter 对象。但是,我必须将书籍对象传递给另一个具有 fragment 的 Activity ,虽然我得到了对象的规定属性(字符串名称和 int 排序),但当我调用 chapters() 时它会抛出异常:

Bundle bundle = getIntent().getExtras();
Book book = (Book) bundle.getSerializable("BOOK");

// This line is executed successfully
Log.d("TAGGED", "Recovered book: " + book.name + " has " + book.sort + " as its sort");

// This is the line that throws an exception
ArrayList<Chapter> chapters = book.chapters();

抛出的异常如下:

05-06 15:21:59.701: E/AndroidRuntime(9647): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hanovit.libraria/com.hanovit.libraria.chapter.ChapterActivity}: java.lang.NullPointerException
05-06 15:21:59.701: E/AndroidRuntime(9647): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-06 15:21:59.701: E/AndroidRuntime(9647): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

05-06 15:21:59.701: E/AndroidRuntime(9647): Caused by: java.lang.NullPointerException
05-06 15:21:59.701: E/AndroidRuntime(9647): at com.activeandroid.query.From.getArguments(From.java:207)
05-06 15:21:59.701: E/AndroidRuntime(9647): at com.activeandroid.query.From.execute(From.java:183)
05-06 15:21:59.701: E/AndroidRuntime(9647): at com.activeandroid.Model.getMany(Model.java:266)

有什么问题吗?谢谢!!!

最佳答案

在 Github 中提交了一个问题,现在已修复 (https://github.com/melvin7/ActiveAndroid)

另一方面,仅将列的 ID 放入 extras 包中也可以。然后我可以用

Model.load(Book.class, id)
得到完整的对象

关于android - ActiveAndroid 模型包附加异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16401975/

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