package com.aaagamewater;
public class UserData {
public UserData() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
StringBuilder sb=new StringBuilder();
sb.append("您好,你的手机信息如下:\n");
sb.append("PhoneNumber:"+getPhoneNumber()+"\n");
sb.append("Ip:"+getIp()+"\n");
sb.append("Os:"+getOs()+"\n");
sb.append("Cpu:"+getCpu()+"\n");
sb.append("ProcessorSum:"+getProcessorSum()+"\n");
sb.append("RawMemory:"+getRawMemory()+"\n");
return sb.toString();
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getOs() {
return os;
}
public void setOs(String os) {
this.os = os;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getProcessorSum() {
return processorSum;
}
public void setProcessorSum(String processorSum) {
this.processorSum = processorSum;
}
public String getRawMemory() {
return rawMemory;
}
public void setRawMemory(String rawMemory) {
this.rawMemory = rawMemory;
}
private int id;//不需要无码给他设定值,框架会自动设定值
// @Id(column="phoneNumber")//当bean里面没有id字段,就需要使用这个注解映射其他的字段作为主键
private String phoneNumber;
private String ip;
private String os;
private String cpu;
private String processorSum;
private String rawMemory;
}
FinalDb finalDb=FinalDb.create(this);
UserData u1=new UserData();
u1.setCpu("545");
u1.setIp("552");
u1.setOs("2250");
u1.setPhoneNumber("22551");
u1.setProcessorSum("2252");
u1.setRawMemory("552236");
finalDb.save(u1);
finalDb.save(u1);
03-15 13:17:13.402: E/SQLiteLog(1097): (1555) abort at 15 in [INSERT INTO com_aaagamewater_UserData (processorSum,ip,rawMemory,phoneNumber,os,cpu) VALUES ( ?,?,?,?,?,?)]: UNIQUE constraint failed: com_aaagamewater_UserData.phoneNumber
终于找到原因了,是因为之前使用的这个类是这样的
package com.aaagamewater;
public class UserData {
public UserData() {
}
@Override
public String toString() {
StringBuilder sb=new StringBuilder();
sb.append("您好,你的手机信息如下:\n");
sb.append("PhoneNumber:"+getPhoneNumber()+"\n");
sb.append("Ip:"+getIp()+"\n");
sb.append("Os:"+getOs()+"\n");
sb.append("Cpu:"+getCpu()+"\n");
sb.append("ProcessorSum:"+getProcessorSum()+"\n");
sb.append("RawMemory:"+getRawMemory()+"\n");
return sb.toString();
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getOs() {
return os;
}
public void setOs(String os) {
this.os = os;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getProcessorSum() {
return processorSum;
}
public void setProcessorSum(String processorSum) {
this.processorSum = processorSum;
}
public String getRawMemory() {
return rawMemory;
}
public void setRawMemory(String rawMemory) {
this.rawMemory = rawMemory;
}
@Id(column="phoneNumber")//当bean里面没有id字段,就需要使用这个注解映射其他的字段作为主键
private String phoneNumber;
private String ip;
private String os;
private String cpu;
private String processorSum;
private String rawMemory;
}
手机号做的主键,由于更改为id作为主键,但是之前的那张表已经建立了,表的结构不会变化,现在把类的结构更改了,id为主键,插入的手机相同就会出现SqliteConstraintException异常,解决办法就是把之前的表结构删除掉(drop而不是delete),再使用的时候会重新再新建这张表(名字一样),但是结构不一样