title: java.lang.NullPointerException: Attempt to invoke virtual methodon a null object reference
body: <p>So I'm working on a personal app that displays JSON data using CardView and RecycleView, however I'm constantly getting this NullPointerException and I have no idea how I should approach to debug this and I could really use some help.</p>
  
  <p>These are the errors I'm getting</p>
  
  <pre><code>    {java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brokenbroadcast.nba_project/com.brokenbroadcast.nba_project.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.brokenbroadcast.nba_project.NBA.getGameList()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3149)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
    at android.app.ActivityThread.access$1000(ActivityThread.java:197)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6891)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.brokenbroadcast.nba_project.NBA.getGameList()' on a null object reference
    at com.brokenbroadcast.nba_project.MainActivity.onCreate(MainActivity.java:52)
    at android.app.Activity.performCreate(Activity.java:6550)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:197) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:145) 
    at android.app.ActivityThread.main(ActivityThread.java:6891) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
  </code></pre>
  
  <p>From my understanding it is having problem with my code at MainActivity.java:52.
  Here is my MainActivity.java</p>
  
  
  
  <pre><code>import android.content.Context;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.Toast;
  
  import com.squareup.okhttp.Call;
  import com.squareup.okhttp.Callback;
  import com.squareup.okhttp.OkHttpClient;
  import com.squareup.okhttp.Request;
  import com.squareup.okhttp.Response;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
  private List&lt;Game&gt; gameList;
  private NBA mNBA;
  public static final String TAG = MainActivity.class.getSimpleName();
  public static final String mScoreboardUrl = "http://data.nba.com/5s/json/cms/noseason/scoreboard/20160116/games.json";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.content_main);
      RecyclerView recList = (RecyclerView) findViewById(R.id.cardList);
      recList.setHasFixedSize(true);
      LinearLayoutManager llm = new LinearLayoutManager(this);
      llm.setOrientation(LinearLayoutManager.VERTICAL);
      recList.setLayoutManager(llm);
      gameList = new ArrayList&lt;Game&gt;();
      setUpGames();
  
      GameAdapter ca = new GameAdapter(mNBA.getGameList());
      recList.setAdapter(ca);
  }
  
  
  
  private void setUpGames() {
      if (isNetworkAvailable()) {
          OkHttpClient client = new OkHttpClient();
          Request request = new Request.Builder().url(mScoreboardUrl).build();
          Call call = client.newCall(request);
          call.enqueue(new Callback() {
              @Override
              public void onFailure(Request request, IOException e) {
                  alertUserAboutError();
              }
  
              @Override
              public void onResponse(Response response) throws IOException {
                  try {
                      String jsonData = response.body().string();
                      if (response.isSuccessful()) {
                          mNBA = parseNBADetails(jsonData);
                      } else {
                          alertUserAboutError();
                      }
                  } catch (IOException e) {
                  } catch (JSONException j) {
                  }
              }
          });
      } else {
          Toast.makeText(this, getString(R.string.network_unavailable_message),
                  Toast.LENGTH_LONG).show();
      }
  }
  
  
  private void alertUserAboutError() {
      AlertDialogFragment dialog = new AlertDialogFragment();
      dialog.show(getFragmentManager(), "error_dialog");
  }
  
  private boolean isNetworkAvailable() {
      ConnectivityManager manager = (ConnectivityManager)
              getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = manager.getActiveNetworkInfo();
      boolean isAvailable = false;
      if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
          isAvailable = true;
      }
  
      return isAvailable;
  
  }
  
  private NBA parseNBADetails(String jsonData) throws JSONException {
  
      NBA nba = new NBA();
      nba.setGameList(parseGames(jsonData));
  
      return nba;
  }
  
  private List&lt;Game&gt; parseGames(String jsonData) throws JSONException {
      JSONObject sports_content = new JSONObject(jsonData);
      JSONObject schedule = sports_content.getJSONObject("sports_content");
      JSONObject gameArray = schedule.getJSONObject("games");
      JSONArray data = gameArray.getJSONArray("game");
  
      List&lt;Game&gt; gameList = new ArrayList&lt;Game&gt;();
      for (int i = 0; i &lt; data.length(); i++) {
          Game game = new Game();
          JSONObject jsonGame = data.getJSONObject(i);
  
          JSONObject jsonVisitor = jsonGame.getJSONObject("visitor");
          game.setVisitorTeamName(jsonVisitor.getString("nickname"));
          game.setVisitorScore(jsonVisitor.getInt("score"));
          game.setVisitorTeamLocation(jsonVisitor.getString("city"));
  
          JSONObject jsonHome = jsonGame.getJSONObject("home");
          game.setHomeTeamLocation(jsonHome.getString("city"));
          game.setHomeTeamName(jsonHome.getString("nickname"));
          game.setHomeScore(jsonHome.getInt("score"));
  
          Log.i(TAG, game.getHomeScore() + "");
  
          gameList.add(game);
      }
      return gameList;
  }
  }
  </code></pre>
  
  <p>This is my class NBA.java
  </p>
  
  <pre><code>public class NBA {
  private List&lt;Game&gt; mGameList;
  
  public List&lt;Game&gt; getGameList() {
      return mGameList;
  }
  
  public void setGameList(List&lt;Game&gt; gameList) {
      mGameList = gameList;
  }
  }
  </code></pre>
  
  <p>This is my Game.java</p>
  
  <pre><code>public class Game {
  
  
      private int mHomeScore;
      private int mVisitorScore;
      private String mHomeTeamLocation;
      private String mHomeTeamName;
      private String mVisitorTeamLocation;
      private String mVisitorTeamName;
  
  
      public String getHomeTeamLocation() {
          return mHomeTeamLocation;
      }
  
      public Game(){}
  
      public void setHomeTeamLocation(String homeTeamLocation) {
          mHomeTeamLocation = homeTeamLocation;
      }
  
      public String getHomeTeamName() {
          return mHomeTeamName;
      }
  
      public void setHomeTeamName(String homeTeamName) {
          this.mHomeTeamName = homeTeamName;
      }
  
      public String getVisitorTeamLocation() {
          return mVisitorTeamLocation;
      }
  
      public void setVisitorTeamLocation(String visitorTeamLocation) {
          mVisitorTeamLocation = visitorTeamLocation;
      }
  
      public String getVisitorTeamName() {
          return mVisitorTeamName;
      }
  
      public void setVisitorTeamName(String visitorTeamName) {
          mVisitorTeamName = visitorTeamName;
      }
  
  
      public String getTitle() {
          return getHomeTeam() + " vs. " + getVisitorTeam();
      }
  
      public String getHomeTeam() {
  
          return mHomeTeamLocation+" " +mHomeTeamName;
      }
  
      public String getVisitorTeam() {
          return mVisitorTeamLocation+" "+mVisitorTeamName;
      }
  
  
      public int getHomeScore() {
          return mHomeScore;
      }
  
      public void setHomeScore(int homeScore) {
          mHomeScore = homeScore;
      }
  
      public int getVisitorScore() {
          return mVisitorScore;
      }
  
      public void setVisitorScore(int visitorScore) {
          mVisitorScore = visitorScore;
      }
  
  
  }
  </code></pre>
  
  <p>My GameAdapter.java</p>
  
  <pre><code>    package com.brokenbroadcast.nba_project;
  
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Created by steven on 1/16/2016.
   */
  public class GameAdapter extends RecyclerView.Adapter&lt;GameAdapter.GameViewHolder&gt; {
  
      private List&lt;Game&gt; mGameList = new ArrayList&lt;Game&gt;();
  
      public GameAdapter(List&lt;Game&gt; gameList){
          mGameList=gameList;
      }
  
      @Override
      public GameViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent, false);
          return new GameViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(GameViewHolder holder, int position) {
          Game curGame = mGameList.get(position);
  
          holder.vHomeScore.setText(curGame.getHomeScore()+"");
          holder.vVisitorScore.setText(curGame.getVisitorScore()+"");
          holder.vTitle.setText(curGame.getTitle());
          holder.vVisitorTeam.setText(curGame.getVisitorTeam());
      }
  
      @Override
      public int getItemCount() {
          return mGameList.size();
      }
  
      public class GameViewHolder extends RecyclerView.ViewHolder {
          private TextView vHomeTeam;
          private TextView vVisitorTeam;
          private TextView vTitle;
          private TextView vHomeScore;
          private TextView vVisitorScore;
  
  
          public GameViewHolder(View v) {
              super(v);
              vHomeTeam = (TextView) v.findViewById(R.id.homeTeam);
              vVisitorTeam = (TextView) v.findViewById(R.id.visitorTeam);
              vHomeScore = (TextView) v.findViewById(R.id.homeScore);
              vVisitorScore = (TextView) v.findViewById(R.id.visitorScore);
              vTitle = (TextView) v.findViewById(R.id.gameTitle);
          }
      }
  }
  </code></pre>
  
  <p>If anyone could help me I will really appreciate it.  </p>