Android 缺少意向传递OrmLite对象ID值?;

Android 缺少意向传递OrmLite对象ID值?;,android,android-intent,ormlite,Android,Android Intent,Ormlite,接收传递的消息的详细信息活动 Intent intent = new Intent(NoticeActivity.this, NoticeDetailActivity.class); intent.putExtra("noticInfo", info); HPLog.d(HPLog.SSX_TAG, "put:" + info.toString()); NoticeActi

接收传递的消息的详细信息活动

  Intent intent = new Intent(NoticeActivity.this, NoticeDetailActivity.class);
                    intent.putExtra("noticInfo", info);
                    HPLog.d(HPLog.SSX_TAG, "put:" + info.toString());
                    NoticeActivity.this.startActivity(intent);
但结果是

ssx:(NoticeActivity.java:174)→put:NoticeBody{id=1,userId='19645238',isRead=true,content='message',title='title',time='20170510175931',noticeId='375905',lastUpdateTime='20170510175931'}


ssx:(NoticeDetailActivity.java:42)→get:NoticeBody{id=0,userId='19645238',isRead=true,content='content',title='title',time='20170510175931',noticeId='375905',lastUpdateTime='20170510175931'}

您的
id
属性未从地块对象读写

你应该:

    NoticeBody notice = getIntent().getParcelableExtra("noticInfo");
    if (notice != null) {
        HPLog.d(HPLog.SSX_TAG, "get:" + notice.toString());
}
@覆盖
公共无效写入包裹(包裹目的地,内部标志){

dest.writeString(this.id);//当id属性没有GET方法时,会发生这种情况,导致每次对象都是默认值0

protected NoticeBody(Parcel in) {
    this.id = in.readInt();  // <-- and add this line
    this.userId = in.readString();
导入android.os.packet;
导入com.j256.ormlite.field.DatabaseField;
导入com.j256.ormlite.table.DatabaseTable;
/**
*
*@email:emotiona_xiaoshi@126.com
*@descripe:描述当前类的功能
*/
@数据库表(tableName=“t_notice”)
公共类noticebook实现了android.os.Parcelable{
@数据库字段(generatedId=true)
私有int-id;
@数据库字段
私有字符串用户标识;
@数据库字段
私有布尔值isRead=false;
@数据库字段
私有字符串内容;
@数据库字段
私有字符串标题;
@数据库字段
私有字符串时间;
@数据库字段
私有字符串标识;
@数据库字段
私有字符串lastUpdateTime;
public int getId(){//添加此方法
返回id;
}
公共字符串getLastUpdateTime(){
返回lastUpdateTime;
}
public void setLastUpdateTime(字符串lastUpdateTime){
this.lastUpdateTime=lastUpdateTime;
}
公共字符串getUserId(){
返回用户标识;
}
public void setUserId(字符串userId){
this.userId=userId;
}
公共布尔值isRead(){
返回isRead;
}
公共void setRead(布尔读取){
isRead=读取;
}
公共字符串getContent(){
返回内容;
}
公共void setContent(字符串内容){
this.content=内容;
}
公共字符串getTitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共字符串getTime(){
返回时间;
}
公共无效设置时间(字符串时间){
这个时间=时间;
}
公共字符串getNoticeId(){
返回通知ID;
}
公共void setNoticeId(字符串noticeId){
this.noticeId=noticeId;
}
公共布告{
}
@凌驾
公共布尔等于(对象o){
如果(this==o)返回true;
如果(o==null | | getClass()!=o.getClass())返回false;
通知体that=(通知体)o;
如果(userId!=null?!userId.equals(that.userId):that.userId!=null)返回false;
return noticeId!=null?noticeId.equals(that.noticeId):that.noticeId==null;
}
@凌驾
公共int hashCode(){
int result=userId!=null?userId.hashCode():0;
result=31*result+(noticeId!=null?noticeId.hashCode():0);
返回结果;
}
@凌驾
公共字符串toString(){
返回“NoticeBody{“+”id=“+id+”,userId=”“+userId+”\''+”,isRead=“+isRead+”,content=”+content+'\''+”,title=“+title+'\''+”,time=“+time+'\''+”,noticeId=“+noticeId+'\''+”,lastUpdateTime=“+lastUpdateTime+'\''+'''}”;
}
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeInt(此.id);
dest.writeString(this.userId);
dest.writeByte(this.isRead?(字节)1:(字节)0);
目的写入内容(此内容);
目的书面限制(本标题);
目的写入限制(本次);
dest.writeString(this.noticeId);
dest.writeString(this.lastUpdateTime);
}
受保护的布告簿(包裹内){
this.id=in.readInt();
this.userId=in.readString();
this.isRead=in.readByte()!=0;
this.content=in.readString();
this.title=in.readString();
this.time=in.readString();
this.noticeId=in.readString();
this.lastUpdateTime=in.readString();
}
公共静态最终创建者=新创建者(){
@凌驾
公共公告库createFromParcel(地块源){
返回新的公告(来源);
}
@凌驾
公共公告库[]新数组(整数大小){
返回新的布告簿[大小];
}
};
}

谢谢您的回答,我忘记了id属性get方法
@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.id); // <-- add this line
    dest.writeString(this.userId);
protected NoticeBody(Parcel in) {
    this.id = in.readInt();  // <-- and add this line
    this.userId = in.readString();
import android.os.Parcel;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
 *
 * @email:emotiona_xiaoshi@126.com
 * @describe:Describe the function  of the current class
 */
@DatabaseTable(tableName = "t_notice")
public class NoticeBody implements android.os.Parcelable {
    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField
    private String userId;
    @DatabaseField
    private boolean isRead = false;
    @DatabaseField
    private String content;
    @DatabaseField
    private String title;
    @DatabaseField
    private String time;
    @DatabaseField
    private String noticeId;
    @DatabaseField
    private String lastUpdateTime;

    public int getId() {//add this method
        return id;
    }


    public String getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(String lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getNoticeId() {
        return noticeId;
    }

    public void setNoticeId(String noticeId) {
        this.noticeId = noticeId;
    }

    public NoticeBody() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        NoticeBody that = (NoticeBody) o;

        if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false;
        return noticeId != null ? noticeId.equals(that.noticeId) : that.noticeId == null;

    }

    @Override
    public int hashCode() {
        int result = userId != null ? userId.hashCode() : 0;
        result = 31 * result + (noticeId != null ? noticeId.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "NoticeBody{" + "id=" + id + ", userId='" + userId + '\'' + ", isRead=" + isRead + ", content='" + content + '\'' + ", title='" + title + '\'' + ", time='" + time + '\'' + ", noticeId='" + noticeId + '\'' + ", lastUpdateTime='" + lastUpdateTime + '\'' + '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.userId);
        dest.writeByte(this.isRead ? (byte) 1 : (byte) 0);
        dest.writeString(this.content);
        dest.writeString(this.title);
        dest.writeString(this.time);
        dest.writeString(this.noticeId);
        dest.writeString(this.lastUpdateTime);
    }

    protected NoticeBody(Parcel in) {
        this.id = in.readInt();
        this.userId = in.readString();
        this.isRead = in.readByte() != 0;
        this.content = in.readString();
        this.title = in.readString();
        this.time = in.readString();
        this.noticeId = in.readString();
        this.lastUpdateTime = in.readString();
    }

    public static final Creator<NoticeBody> CREATOR = new Creator<NoticeBody>() {
        @Override
        public NoticeBody createFromParcel(Parcel source) {
            return new NoticeBody(source);
        }

        @Override
        public NoticeBody[] newArray(int size) {
            return new NoticeBody[size];
        }
    };
}