2016-06-16 1 views
0

Je suis newbie à android et de travailler sur une application de démonstration avec deux écrans pour passer une donnée de l'une à l'autre activité, Au cours de cette exception, je reçois ci-dessous,Je reçois java.lang.runtimeexception parcelable rencontré ioexception écriture objet sérialisable

java.lang.RuntimeException: Parcelable IOException écriture rencontré objet sérialisable (name = one.tusk.stush.connect.Post)

Code

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; 
    } 

Poster

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; 
     } 
    } 

} 

quelqu'un peut-il me s'il vous plaît aider à résoudre ce problème.

+0

Mettez la classe 'Post' dans la question. – Ironman

+0

Qu'est-ce que la classe 'Post'? – Apurva

+0

@Ironman - Quelle classe? –

Répondre

0

Mettre en œuvre Serializable sur la classe de modèle Post. Cela va corriger l'erreur.

public class Post implements Serializable { 
+0

juste mettre en œuvre? Ou toute autre mise en œuvre que je dois faire? S'il vous plaît s'il vous plaît aidez-moi. –

+0

Non il suffit d'ajouter cette ligne .. Aucun autre code nécessaire – Sanoop

+0

Quel est votre classe 'BaseObject' ?? – Sanoop

0

Faites votre classe BaseObject met également en œuvre Serializable comme celui-ci

public class BaseObject implements Serializable 
{ 
} 

Si encore problème est là puis mettez à jour votre question avec classe BaseObject.

+0

Hey, j'ai posté mon BaseObject ot mon question..Please voir, me aider pls –

+0

Bonjour, j'ai trouvé la cause, quand je l'ai ajouté' \t \t publique statique JSONObject getJSONFromJSONObject (JSONObject JsonObject, String key) { \t \t \t \t valeur JSONObject = null; \t \t try { \t \t \t valeur = jsonObject.getJSONObject (clé); \t \t} catch (Exception e) {} \t \t \t \t valeur de retour; \t} 'dans mon objet de base j'ai trouvé cette exception, –