title: Android: NPE when calling getIntent().getParcelableExtra() twice in a DetailActivity (2 different json model classes both with Id field)
body: <p>Recently began experimenting with Retrofit. Specifically, with <a href="http://docs.themoviedb.apiary.io/#" rel="nofollow">themoviedb.org API</a>.</p>
  
  <p>Currently displaying list of popular movies in <code>MainActivity</code>. Clicking a movie launches the <code>DetailActivity</code> and displays some details for that particular movie including Cast and Crew. </p>
  
  <p>Clicking a Cast member launches a <code>FilmographyActivity</code> - displaying the movie poster for each movie that particular actor has been in. </p>
  
  <p><strong>Problem:</strong>
  I'm then trying to click a movie from the <code>FilmographyActivity</code> --> grab that particular movie's unique ID --> and pass it into the <code>DetailsActivity</code>. (Or is it possible to set the ID from <code>List&lt;ActorCast&gt;</code> equal to the ID from <code>List&lt;MovieInfo&gt;</code>? These are two of the classes I've generated from using <a href="http://www.jsonschema2pojo.org/" rel="nofollow">http://www.jsonschema2pojo.org/</a>)</p>
  
  <p>Relevant code:</p>
  
  <p>MovieDetailActivity.java</p>
  
  <pre><code>public static final String EXTRA_MOVIE = "movie";
  public static final String EXTRA_ACTOR = "actor";
  MovieInfo mMovieInfo;
  ActorCast mActorCast;
  
  @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_movie_detail);
  
          // Here's where I think/know I'm screwing things up:
          if (getIntent().hasExtra(EXTRA_MOVIE)) {
              mMovieInfo = getIntent().getParcelableExtra(EXTRA_MOVIE);
          } else if (getIntent().hasExtra(EXTRA_ACTOR)){
              mActorCast = getIntent().getParcelableExtra(EXTRA_ACTOR);
          } else {
              throw new IllegalArgumentException("Detail Activity IllegalArgumentException");
      }
  
      final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      if (getSupportActionBar() != null) {
          getSupportActionBar().setTitle(mMovieInfo.getTitle());
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
  
      title.setText(mMovieInfo.title);
      description.setText(mMovieInfo.overview);
      voteCount.setText(String.valueOf(mMovieInfo.voteCount));
  
      .....
  
  } // end onCreate
  </code></pre>
  
  <p>And part of the PopularMoviesAdapter:</p>
  
  <pre><code>    private Context mContext;
      private List&lt;MovieInfo&gt; list;
      private LayoutInflater inflater;
  
      public MovieAdapter(Context context) {
      inflater = LayoutInflater.from(context);
      this.mContext = context;
      list = new ArrayList&lt;&gt;();
  }
  
  @Override
      public void onBindViewHolder(final MyViewHolder holder, final int position) {
          final MovieInfo currentMovie = list.get(position);
  
      ...
          holder.moviePoster.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "Clicked: " + currentMovie.getId(), Toast.LENGTH_SHORT).show();
              int position = holder.getAdapterPosition();
              Intent intent = new Intent(mContext, MovieDetailActivity.class);
              intent.putExtra(MovieDetailActivity.EXTRA_MOVIE, list.get(position));
              mContext.startActivity(intent);
  
          }
      });
  } // end onBindViewHolder
  </code></pre>
  
  <p>And part of the FilmographyAdapter:</p>
  
  <pre><code>private Context mContext;
  private LayoutInflater inflater;
  private List&lt;ActorCast&gt; list;
  
  public ActorAdapter(Context context, List&lt;ActorCast&gt; actorCast){
      inflater = LayoutInflater.from(context);
      this.mContext = context;
      this.list = actorCast;
  }
  
  .....
  
  @Override
  public void onBindViewHolder(final ActorViewHolder holder, final int position) {
      final ActorCast actor = list.get(position);
  
          holder.actorCreditMovieImage.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "Clicked: " + actor.getId(), Toast.LENGTH_SHORT).show();
              Intent intent = new Intent(mContext, MovieDetailActivity.class);
              //intent.putExtra(MovieDetailActivity.EXTRA_ACTOR, actorInfoList.get(position).getId());
  
              intent.putExtra(MovieDetailActivity.EXTRA_ACTOR, list.get(position).id);
              mContext.startActivity(intent);
          }
      });
  </code></pre>
  
  <p>I probably need to take a step back and look at the "big picture" of what's going on - been staring at it for a bit too long. </p>
  
  <p>Here's what my Interface calls look like:</p>
  
  <pre><code>public interface PopMoviesInterface {
  
      @GET("3/discover/movie?sort_by=popularity.desc&amp;api_key=308be8a6ec40318471fb3c4d177c0382")
      Call&lt;MovieResult&gt; allItems(@Query("page") int page);
  
      @GET("3/person/{id}/movie_credits")
      Call&lt;ActorResult&gt; showActorHistory(@Path("id") String id, @Query("api_key") String key);
  
      @GET("3/movie/{movie}/credits")
      Call&lt;CreditsList&gt; listCredits(@Path("movie") String movie, @Query("api_key") String key);
  
  }
  </code></pre>
  
  <p>And the logcat:</p>
  
  <pre><code>04-27 21:47:06.596 19486-19486/com.example.user.retrofit2moviedemo E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.user.retrofit2moviedemo, PID: 19486
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.retrofit2moviedemo/com.example.user.retrofit2moviedemo.MovieDetailActivity}: java.lang.IllegalArgumentException: Detail Activity IllegalArgumentException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: java.lang.IllegalArgumentException: Detail Activity IllegalArgumentException
  at com.example.user.retrofit2moviedemo.MovieDetailActivity.onCreate(MovieDetailActivity.java:101)
  at android.app.Activity.performCreate(Activity.java:6251)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <p>Any suggestions, advice or a point in the right direction is appreciated.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here are my POJOs. Note: Not all of the "fields" (am I using this term right?) in MovieInfo are found in ActorCast, such as "overview" "voteCount" and a few others. So, when clicking a movie in the FilmographyActivity, it won't just automatically get the overview etc since that field isn't found in ActorCast.java. </p>
  
  <p><code>MovieInfo.java</code> (which is tied to <code>MovieResult.java</code></p>
  
  <pre><code>public class MovieInfo implements Parcelable {
  
      @SerializedName("poster_path")
      @Expose
      public String posterPath;
      @SerializedName("adult")
      @Expose
      public Boolean adult;
      @SerializedName("overview")
      @Expose
      public String overview;
      @SerializedName("release_date")
      @Expose
      public String releaseDate;
      @SerializedName("id") //THIS IS THE UNIVERSAL MOVIE ID
      @Expose
      public Integer id;
      @SerializedName("original_title")
      @Expose
      public String originalTitle;
      ... // Not showing Other fields like popularity, voteCount etc to save space
      ...
      // getters and setters
  
      public static final Creator&lt;MovieInfo&gt; CREATOR = new Creator&lt;MovieInfo&gt;() {
          @Override
          public MovieInfo createFromParcel(Parcel in) {
              return new MovieInfo(in);
          }
          @Override
          public MovieInfo[] newArray(int size) {
              return new MovieInfo[size];
          }
      };
  
      public MovieInfo(Parcel in){
          id = in.readInt();
          title = in.readString();
          posterPath = in.readString();
          overview = in.readString();
          backdropPath = in.readString();
          voteAverage = in.readDouble();
          voteCount = in.readInt();
          releaseDate = in.readString();
      }
  
      public MovieInfo(int id, String title, String poster, String plot, 
                   double rating, String release, String backdrop, int voteCount) {
          this.id = id;
          this.title = title;
          this.posterPath = poster;
          this.overview = plot;
          this.backdropPath = backdrop;
          this.voteAverage = rating;
          this.voteCount = voteCount;
          this.releaseDate = release;
      }
  
          @Override
          public int describeContents() {
              return 0;
          }
  
          @Override
          public void writeToParcel(Parcel parcel, int i) {
              parcel.writeInt(id);
              parcel.writeString(title);
              parcel.writeString(posterPath);
              parcel.writeString(overview);
              parcel.writeString(backdropPath);
              parcel.writeDouble(voteAverage);
              parcel.writeInt(voteCount);
              parcel.writeString(releaseDate);
          }
  </code></pre>
  
  <p>MovieResult.java</p>
  
  <pre><code>@Generated("org.jsonschema2pojo")
  public class MovieResult {
  
      @SerializedName("page")
      @Expose
      public Integer page;
      @SerializedName("results")
      @Expose
      public List&lt;MovieInfo&gt; results = new ArrayList&lt;MovieInfo&gt;();
      @SerializedName("total_results")
      @Expose
      public Integer totalResults;
      @SerializedName("total_pages")
      @Expose
      public Integer totalPages;
      // getters and setters
  </code></pre>
  
  <p>The two below deal with the Filmography.</p>
  
  <p>ActorCast.java</p>
  
  <pre><code>@Generated("org.jsonschema2pojo")
  public class ActorCast implements Parcelable {
  
      @SerializedName("adult")
      @Expose
      public Boolean adult;
      @SerializedName("character")
      @Expose
      public String character;
      @SerializedName("credit_id")
      @Expose
      public String creditId;
      @SerializedName("id") //THIS IS THE UNIVERSAL MOVIE ID
      @Expose
      public Integer id;
      // few other fields not included to save space. 
      // getters and setters
      // Parcelable methods here
  </code></pre>
  
  <p>And ActorResult.java</p>
  
  <pre><code>@Generated("org.jsonschema2pojo")
  public class ActorResult {
  
      @SerializedName("cast")
      @Expose
      public List&lt;ActorCast&gt; cast = new ArrayList&lt;ActorCast&gt;();
      @SerializedName("crew")
      @Expose
      public List&lt;ActorCrew&gt; crew = new ArrayList&lt;ActorCrew&gt;();
      @SerializedName("id") //THIS IS THE ACTOR ID
      @Expose
      public Integer id;
  </code></pre>