When trying to replace

model = getIntent().getParcelableExtra("key"); 

On

 model = getIntent().getSerializableExtra("key"); 

I am underlined by a line with an error about a type mismatch

Required com.project.app.Person.person

but

Found java.io.Serializable

. Please tell me how to fix it.

Model class:

 public class Model implements Serializable { @SerializedName("name") @Expose private String name; @SerializedName("products") @Expose private Integer products; public String getName() { return name; public Integer getProducts() { return products; } 

In the adapter I transmit as follows

 public void startActivity(TopStoriesAdapter.ViewHolder viewHolder) { Intent intent = new Intent(context, TopStoryDetailActivity.class); intent.putExtra("key", topStoriesList.get(viewHolder.getAdapterPosition())); context.startActivity(intent); } 
  • What class is the model object? Show this class. - post_zeew
  • @post_zeew updated the question. - Inkognito
  • What kind of items are in topStoriesList ? Show the line with the declaration of this variable. - post_zeew
  • @post_zeew private list <Model> topStoriesList; c Parceable everything worked correctly, just need to change to Serializable - Inkognito

1 answer 1

If you decide to use all the same class Serializable , then start doing in order:

 Model model= new Model(); Intent i = new Intent(context, TopStoryDetailActivity.class); i.putExtra("key", model); startActivity(i); 

in TopStoryDetailActivity.class :

 Model model = (Model) getIntent().getSerializableExtra("key"); 

And of course once again check your model so that it implements what you need.

 public class Model implements Serializable { } 

I hope it will be useful.

  • the error disappeared, but as for me in putExtra instead of model, pass to topStoriesList.get(viewHolder.getAdapterPosition()); ? - Inkognito
  • one
    @Inkognito leave your startActivity method unchanged. Should work. This is your Model stored in topStories. - Morozov