2013-05-06 58 views
2

夥計們!我寫了一個Book類,它有章節對象(一對多關係)。它實現了公共列表章節()的方法,如文檔中所述。這是Book.javaActiveAndroid模型捆綁額外異常

@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; 
} 
} 

在主要活動上,我可以成功地獲得章節對象。但是,我必須將書對象傳遞給另一個具有片段的活動,儘管我獲得了該對象的聲明屬性(String name和int sort),但在調用章節()時拋出異常:

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) 

任何想法有什麼不好?謝謝!!!

回答

2

在Github上提交一個問題,現在是固定的(https://github.com/melvin7/ActiveAndroid

在另一方面,投入的額外捆綁只有列的ID也有效。然後我可以用

Model.load(Book.class, id)