2016-06-16 25 views
0

我是新手到android和工作在一個演示應用程序與兩個屏幕將數據從一個傳遞到另一個活動,在此期間我得到異常,我得到java.lang.runtimeexception可parcelable遇到ioexception編寫可序列化的對象

了java.lang.RuntimeException:Parcelable遇到IOException的寫入 序列化的對象(名稱= one.tusk.stush.connect.Post)

代碼

Intent intentPostDetail = new Intent(PostListItem.this.getContext(), NewPostDetailActivity.class); 
       Post post = mPost; 
       System.out.print("========MY POST IS======>" + mPost.toString()); 
       intentPostDetail.putExtra("Post", post); 
       intentPostDetail.putExtra("flag", "post"); 
      mContext.startActivity(intentPostDetail); 

baseObject

public class BaseObject { 

    static DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 

    public static Date getDateFromJSONObject(JSONObject jsonObject, String key) { 

     String value = ""; 
     Date date = null; 
     try { 
      value = jsonObject.getString(key); 
      date = dateFormatter.parse(value); 
     } catch (Exception e) { 
     } 
     return date; 

    } 
    public static String getStringFromJSONObject(JSONObject jsonObject, String key) { 

     String value = ""; 
     try { 
      value = jsonObject.getString(key); 
     } catch (Exception e) { 
     } 
     return value; 
    } 

    public static int getIntFromJSONObject(JSONObject jsonObject, String key) { 

     int value = 0; 
     try { 
      value = jsonObject.getInt(key); 
     } catch (Exception e) { 
     } 
     return value; 
    } 

    public static boolean getBooleanFromJSONObject(JSONObject jsonObject, String key) { 

     boolean value = false; 
     try { 
      value = jsonObject.getBoolean(key); 
     } catch (Exception e) { 
     } 
     return value; 
    } 

    public static double getDoubleFromJSONObject(JSONObject jsonObject, String key) { 

     double value = 0; 
     try { 
      value = jsonObject.getDouble(key); 
     } catch (Exception e) { 
     } 
     return value; 
    } 



    public static JSONObject getJSONFromJSONObject(JSONObject jsonObject, String key) { 

     JSONObject value = null; 
     try { 
      value = jsonObject.getJSONObject(key); 
     } catch (Exception e) { 
     } 
     return value; 
    } 

public class Post extends BaseObject implements Serializable { 

    private static final long serialVersionUID = 1L; 
    public String postTitle; 
    public String postImagePath; 
    public Date postDate; 
    public ArrayList<String> postKeywords; 
    public User postUser; 
    public int postID; 
    public int postLikesCount; 
    public int postCommentsCount; 
    public boolean likedThisPost; 
    public boolean commentedThisPost; 
    public boolean inAlbum; 
    public String timeAgo; 
    public int totalReviews; 
    public String loginuserReviews; 
    int rv_cnt; 
    public double ratingcount; 
    public JSONObject userObj; 
    public int userId; 

    String reviews; 

    public Post(JSONObject jsonObject) { 
     //Log.d("JSOn", jsonObject.toString()); 
     this.postID = getIntFromJSONObject(jsonObject, "postID"); 
     this.postImagePath = getStringFromJSONObject(jsonObject, "postImage"); 
     this.postTitle = getStringFromJSONObject(jsonObject, "postTitle"); 
     this.postDate = getDateFromJSONObject(jsonObject, "postDate"); 
     this.postUser = new User(getJSONFromJSONObject(jsonObject, "user")); 
     this.postLikesCount = getIntFromJSONObject(jsonObject, "totalLikes"); 
     this.postCommentsCount = getIntFromJSONObject(jsonObject, "totalComments"); 
     this.timeAgo = getStringFromJSONObject(jsonObject, "timeAgo"); 
     this.commentedThisPost = getBooleanFromJSONObject(jsonObject, "isCommented"); 
//  userObj = getJSONFromJSONObject(jsonObject, "user"); 
     this.userId = getIntFromJSONObject(jsonObject, "userID"); 
     this.totalReviews = getIntFromJSONObject(jsonObject, "totalReview"); 
     this.ratingcount = getDoubleFromJSONObject(jsonObject, "ratingcount"); 


     int isLiked = getIntFromJSONObject(jsonObject, "isLiked"); 
     if (isLiked == 1) { 
      this.likedThisPost = true; 
     } else { 
      this.likedThisPost = false; 
     } 

     int inAlbum = getIntFromJSONObject(jsonObject, "inAlbum"); 
     if (inAlbum == 1) { 
      this.inAlbum = true; 
     } else { 
      this.inAlbum = false; 
     } 
    } 

} 

任何人都可以請幫我解決這個問題。

+0

在問題中加入'Post'類。 – Ironman

+0

什麼是Post類? – Apurva

+0

@Ironman - 哪一類? –

回答

0

實施Serializable模型類Post。這將修復錯誤。

public class Post implements Serializable { 
+0

只是實現?或者我需要做的更多實現?請幫助我。 –

+0

沒有隻是添加這條線..沒有其他代碼需要 – Sanoop

+0

什麼是你的'BaseObject'類? – Sanoop

0

讓您BaseObject類也實現Serializable這樣

public class BaseObject implements Serializable 
{ 
} 

如果問題依然是那麼有更新BaseObject類你的問題。

+0

嘿,我已經發布我的baseobject加時賽我question..Please看到,幫我請 –

+0

你好,我找到了原因,當我添加了' \t \t公衆靜態JSONObject getJSONFromJSONObject(JSONObject jsonObject,String key){JSONObject jsonObject,String key { \t \t \t \t JSONObject value = null; \t \t嘗試{ \t \t \t value = jsonObject.getJSONObject(key); \t \t}趕上(例外五){ \t \t} \t \t返回值; \t}'在我的基礎對象中,我發現這個異常, –

相關問題