How could i use ActiveAndroid in one class whitch contain a arraylist?
I read the Relationships section,but it's not work. I think there is something wrong with my usage. Anyone could help me?
There are two class.
Originally code like
Class RoundInfo :
public class RoundInfo{
String roundNum;
List<MatchInfo> matchInfos = new ArrayList<MatchInfo>();
public RoundInfo() {
super();
// TODO Auto-generated constructor stub
}
public RoundInfo(String roundNum) {
super();
this.roundNum = roundNum;
matchInfos.add(new MatchInfo("11", "21", "1121"));
}
}
Class MatchInfo:
public class MatchInfo{
String home;
String away;
String sorce;
public MatchInfo() {
super();
}
public MatchInfo(String home, String away, String sorce) {
super();
this.home = home;
this.away = away;
this.sorce = sorce;
}
}
Then i wanna use ActiveAndroid save roundinfo data to db. And make some change like 1.Let my application class extends com.activeandroid.app.Application 2.Add AA_DB_NAME & AA_DB_VERSION to AndroidManifest.xml 3.Modify class MatchInfo & RoundInfo to
Class RoundInfo:
@Table(name = "RoundInfo") public class RoundInfo extends Model {
@Column(name = "roundNum")
String roundNum;
public List<MatchInfo> matchinfos() {
return getMany(MatchInfo.class, "MatchInfo");
}
public RoundInfo() {
super();
// TODO Auto-generated constructor stub
}
public RoundInfo(String roundNum) {
super();
this.roundNum = roundNum;
matchinfos().add(new MatchInfo("11", "21", "1121"));
matchinfos().add(new MatchInfo("12", "22", "1222"));
matchinfos().add(new MatchInfo("13", "23", "1323"));
matchinfos().add(new MatchInfo("14", "24", "1424"));
}
}
Class MatchInfo:
@Table(name = "MatchInfos") public class MatchInfo extends Model {
@Column(name = "home")
String home;
@Column(name = "away")
String away;
@Column(name = "sorce")
String sorce;
public MatchInfo() {
super();
// TODO Auto-generated constructor stub
}
public MatchInfo(String home, String away, String sorce) {
super();
this.home = home;
this.away = away;
this.sorce = sorce;
}
}
Question: When i new the RoundInfo class and save() it use
RoundInfo roundInfo1 = new RoundInfo("1");
roundInfo1.save();
Finally get some errors like
04-01 22:33:37.875: E/AndroidRuntime(14712): FATAL EXCEPTION: main
04-01 22:33:37.875: E/AndroidRuntime(14712): java.lang.NullPointerException
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.query.From.getArguments(From.java:207)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.query.From.execute(From.java:183)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.Model.getMany(Model.java:247)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.RoundInfo.matchinfos(RoundInfo.java:16)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.RoundInfo.
I know the problem is my usage of the method matchinfos(). How to solve it?
Did you solve the issue? If so, how?