2016-06-23 11 views
0

Ich habe einen Beitrag Objekt, das ich auf die Absicht passieren:Android verdirbt meinen String

Log.d("POST_IMAGE", post.image_url); http://localhost:8888/wordpress/wp-content/uploads/2016/06/yudikcflq9lsulgtwncn.jpg

final Intent intent = new Intent(); intent.setClass(host, PostDetail.class); intent.putExtra(PostDetail.EXTRA_POST, (Post) getItem(holder.getAdapterPosition())); host.startActivity(intent);

OnCreate Methode in meinem PostDetail Aktivität:

post = getIntent().getParcelableExtra(EXTRA_POST); Log.d("POST_IMAGE", post.image_url); ��������������S��http://localhost:8888/wordpress/wp-content/uploads/

Nach dem Abrufen meiner image_url, bekomme ich stattdessen diese seltsame Zeichenfolge ��������������S��http://localhost:8888/wordpress/wp-content/uploads/

Der Bildstring erscheint gut, bevor ich die Absicht mache, aber nach seiner Durchfahrt bekomme ich eine fehlerhafte Zeichenfolge. Andere Eigenschaften auf meinem Objekt erscheinen gut. Es ist nur diese Variable.

Edit: My Post Klasse

`Paket my.package.model;

import android.content.res.ColorStateList; 
    import android.os.Parcel; 
    import android.os.Parcelable; 
    import android.support.annotation.ColorInt; 
    import android.text.TextUtils; 

    import java.util.ArrayList; 
    import java.util.Date; 
    import java.util.List; 

public class Beitrag implementiert Parcel {

public final String comment; 
public final String comment_html; 
public final int comment_count; 
public final long views_count; 
public final int vote_count; 
public final Date created_at; 
public final long user_id; 
public final String user_display_name; 
public final String user_portrait_url; 
public final String hostname; 
public final String badge; 
public final String user_job; 
public final List<Comment> comments; 
public final String image_url; 

public Post(long id, 
      String title, 
      String url, 
      String comment, 
      String comment_html, 
      int comment_count, 
      long views_count, 
      int vote_count, 
      Date created_at, 
      long user_id, 
      String user_display_name, 
      String user_portrait_url, 
      String hostname, 
      String badge, 
      String user_job, 
      List<Comment> comments, 
      String image_url) { 
    this.comment = comment; 
    this.comment_html = comment_html; 
    this.comment_count = comment_count; 
    this.views_count = views_count; 
    this.vote_count = vote_count; 
    this.created_at = created_at; 
    this.user_id = user_id; 
    this.user_display_name = user_display_name; 
    this.user_portrait_url = user_portrait_url; 
    this.hostname = hostname; 
    this.badge = badge; 
    this.user_job = user_job; 
    this.comments = comments; 
    this.image_url = image_url; 
} 

protected Post(Parcel in) { 
    super(in.readLong(), in.readString(), in.readString()); 
    comment = in.readString(); 
    comment_html = in.readString(); 
    comment_count = in.readInt(); 
    views_count = in.readLong(); 
    vote_count = in.readInt(); 
    long tmpCreated_at = in.readLong(); 
    created_at = tmpCreated_at != -1 ? new Date(tmpCreated_at) : null; 
    user_id = in.readLong(); 
    user_display_name = in.readString(); 
    user_portrait_url = in.readString(); 
    hostname = in.readString(); 
    badge = in.readString(); 
    user_job = in.readString(); 
    if (in.readByte() == 0x01) { 
     comments = new ArrayList<Comment>(); 
     in.readList(comments, Comment.class.getClassLoader()); 
    } else { 
     comments = null; 
    } 
    image_url = in.readString(); 
} 

public static class Builder { 
    private long id; 
    private String title; 
    private String url; 
    private String comment; 
    private String commentHtml; 
    private int commentCount; 
    private long viewCount; 
    private int voteCount; 
    private Date createdAt; 
    private long userId; 
    private String userDisplayName; 
    private String userPortraitUrl; 
    private String hostname; 
    private String badge; 
    private String userJob; 
    private List<Comment> comments; 
    private String imageUrl; 

    public Builder setId(long id) { 
     this.id = id; 
     return this; 
    } 

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

    public Builder setUrl(String url) { 
     this.url = url; 
     return this; 
    } 

    public Builder setDefaultUrl(long id) { 
     this.url = "https://www.site.co/posts/" + id; 
     return this; 
    } 

    public Builder setComment(String comment) { 
     this.comment = comment; 
     return this; 
    } 

    public Builder setCommentHtml(String comment_html) { 
     this.commentHtml = comment_html; 
     return this; 
    } 

    public Builder setCommentCount(int comment_count) { 
     this.commentCount = comment_count; 
     return this; 
    } 

    public Builder setViewCount(long view_count) { 
     this.viewCount = view_count; 
     return this; 
    } 

    public Builder setVoteCount(int vote_count) { 
     this.voteCount = vote_count; 
     return this; 
    } 

    public Builder setCreatedAt(Date created_at) { 
     this.createdAt = created_at; 
     return this; 
    } 

    public Builder setUserId(long user_id) { 
     this.userId = user_id; 
     return this; 
    } 

    public Builder setUserDisplayName(String user_display_name) { 
     this.userDisplayName = user_display_name; 
     return this; 
    } 

    public Builder setUserPortraitUrl(String user_portrait_url) { 
     this.userPortraitUrl = user_portrait_url; 
     return this; 
    } 

    public Builder setHostname(String hostname) { 
     this.hostname = hostname; 
     return this; 
    } 

    public Builder setBadge(String badge) { 
     this.badge = badge; 
     return this; 
    } 

    public Builder setUserJob(String user_job) { 
     this.userJob = user_job; 
     return this; 
    } 

    public Builder setComments(List<Comment> comments) { 
     this.comments = comments; 
     return this; 
    } 

    public Builder setImageUrl(String image_url) { 
     this.imageUrl = image_url; 
     return this; 
    } 

    public Post build() { 
     return new Post(id, title, url, comment, commentHtml, commentCount, viewCount, voteCount, 
       createdAt, userId, userDisplayName, userPortraitUrl, hostname, badge, 
       userJob, comments, imageUrl); 
    } 

    public static Builder from(Post existing) { 
     return new Builder() 
       .setId(existing.id) 
       .setTitle(existing.title) 
       .setUrl(existing.url) 
       .setComment(existing.comment) 
       .setCommentHtml(existing.comment_html) 
       .setCommentCount(existing.comment_count) 
       .setViewCount(existing.views_count) 
       .setVoteCount(existing.vote_count) 
       .setCreatedAt(existing.created_at) 
       .setUserId(existing.user_id) 
       .setUserDisplayName(existing.user_display_name) 
       .setUserPortraitUrl(existing.user_portrait_url) 
       .setHostname(existing.hostname) 
       .setBadge(existing.badge) 
       .setUserJob(existing.user_job) 
       .setComments(existing.comments) 
       .setImageUrl(existing.image_url); 
    } 
} 

/* Parcelable stuff */ 

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

@Override 
public void writeToParcel(Parcel dest, int flags) { 
    dest.writeLong(id); 
    dest.writeString(title); 
    dest.writeString(url); 
    dest.writeString(comment); 
    dest.writeString(comment_html); 
    dest.writeInt(comment_count); 
    dest.writeInt(vote_count); 
    dest.writeLong(created_at != null ? created_at.getTime() : -1L); 
    dest.writeLong(user_id); 
    dest.writeString(user_display_name); 
    dest.writeString(user_portrait_url); 
    dest.writeString(hostname); 
    dest.writeString(badge); 
    dest.writeString(user_job); 
    if (comments == null) { 
     dest.writeByte((byte) (0x00)); 
    } else { 
     dest.writeByte((byte) (0x01)); 
     dest.writeList(comments); 
    } 
    dest.writeString(image_url); 
} 

@SuppressWarnings("unused") 
public static final Parcelable.Creator<Post> CREATOR = new Parcelable.Creator<Post>() { 
    @Override 
    public Post createFromParcel(Parcel in) { 
     return new Post(in); 
    } 

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

} `

+0

Implementiert Ihr Post Parcelable? – CaseyB

+0

Es tut. Ich habe die Implementierung der Post-Klasse hinzugefügt. –

Antwort

0

Ich denke, das ist Ihr Problem. Sie haben dies in Ihrem writeToParcel()

if (comments == null) { 
    dest.writeByte((byte) (0x00)); 
} else { 
    dest.writeByte((byte) (0x01)); 
    dest.writeList(comments); 
} 
dest.writeString(image_url); 

, die eine Liste von Kommentaren ergänzt, wenn sie da sind, aber wenn Sie nicht über diese Liste überspringen. Im Ersteller laden Sie immer die Liste.

.setBadge(existing.badge) 
.setUserJob(existing.user_job) 
.setComments(existing.comments) 
.setImageUrl(existing.image_url); 

Haben Sie geprüft, ob dies nur auf Beiträge mit Kommentaren passiert?

+0

Oh danke. Ich erkannte, dass ich eine Schreiboperation für 'views_count' knapp oberhalb von' vote_count' übersprungen habe. Ich fügte 'dest.writeLong (views_count);' hinzu und jetzt funktioniert alles gut. –

Verwandte Themen