title: OkHttp http calls work in Java Main, but when I work with android app crashes
body: <p>I'm currently working on an android project that retrieves <code>JSON</code> data from Riot API and parse it. </p>
  
  <p>I'm using <code>OkHttp</code> to get the URL and convert the contents into a string, and then convert into Java Object using <code>GSON</code>. When I run my code in Java's main method, it works perfectly. However, when I'm using Android and run the code on an android phone, the app crashes. 
  The error I get is </p>
  
  <blockquote>
    <p>"java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference"</p>
  </blockquote>
  
  <p>Here are my codes:</p>
  
  <p>This is Android's <code>MainActivity</code>:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Button button = (Button) findViewById(R.id.button);
      button.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      EditText text = (EditText)findViewById(R.id.editText2);
      String value = text.getText().toString();
      if (value.equals("")) {
          Context context = getApplicationContext();
          CharSequence tex = "Field cannot be empty!";
          int duration = Toast.LENGTH_SHORT;
          Toast toast = Toast.makeText(context, tex, duration);
          toast.show();
        } else {
          Summoner.getInstance().setSummonerName(value);
          Intent i = new Intent(this, DisplaySummonerInfo.class);
          startActivity(i);
        }
  }
  }
  </code></pre>
  
  <p>This is the activity I jump to when user inputs a name</p>
  
  <pre><code>public class DisplaySummonerInfo extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.display_summoner);
      GetSummonerID.getUserInfo();
      TextView name = (TextView) findViewById(R.id.textView5);
      TextView id = (TextView) findViewById(R.id.textView6);
      TextView level = (TextView) findViewById(R.id.textView7);
      name.setText(Summoner.getInstance().getSummonerName());
      id.setText(Summoner.getInstance().getSummonerID());
      level.setText(Summoner.getInstance().getSummonerLevel());
  }
  </code></pre>
  
  <p>.This class converts data using <code>OkHttp</code> and <code>GSON</code></p>
  
  <pre><code>public class GetSummonerID {
  
  private static OkHttpClient client = new OkHttpClient();
  
  public static String getJSON(String url) throws IOException {
      Request request = new Request.Builder()
              .url(url)
              .build();
  
      Response response = client.newCall(request).execute();
      return response.body().string();
  }
  
  public static void getUserInfo(){
      String json = null;
      try {
          String url = "https://na1.api.riotgames.com/lol/summoner/v3/summoners/by-name/" + Summoner.getInstance().getSummonerName()
                  + "?api_key=" + Summoner.getInstance().getApiKey();
          json = getJSON(url);
      } catch (Exception e){
          e.printStackTrace();
      }
  
      Gson gson = new Gson();
      SummID summID = gson.fromJson(json, SummID.class);
  
      Summoner.getInstance().setSummonerName(summID.getName());
      Summoner.getInstance().setSummonerID(summID.getId());
      Summoner.getInstance().setSummonerLevel(summID.getSummonerLevel());
  }
  </code></pre>
  
  <p>Thank you in advanced for you help!</p>