title: How to pass context from MainActivity to another class in Android?
body: <p>I am experiencing an issue when trying to pass the context from the MainActivity class to another. Here is the ContextPasser Class. </p>
  
  <pre><code>public class ContextPasser extends Application{
  public Context context;
  public ContextPasser(){
      context = getApplicationContext();
  }}
  </code></pre>
  
  <p>But if I use the context variable in the other class, like this: </p>
  
  <pre><code>Line line = new Line(new ContextPasser().context);
  </code></pre>
  
  <p>I am getting a null pointer exception. I want to get a solution which does not involve passing in a context variable because I have looked at all of the other stackoverflows and they do not seem to help me with that. One of the solutions that I found was: </p>
  
  <pre><code>Context context;
  MyHelperClass(Context context){
  this.context=context;
  }
  </code></pre>
  
  <p>This does not help me because I am calling the Line class which is,</p>
  
  <pre><code>Line line = new Line(new ContextPasser().context);
  </code></pre>
  
  <p>in another class called the GameRunner like so: </p>
  
  <pre><code>public class GameRunner extends Activity {
  Line line = new Line(new ContextPasser().context);
  public void draw(Canvas canvas){
      line.draw(canvas);
      getWindow().getDecorView().setBackgroundColor(Color.BLACK);
  }
  
  public void update(){
      line.update();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So, I want to create a method that will pass the Context without accepting parameters of the Context class themselves. </p>
  
  <p>Please let me know any suggestions or answers. 
  I would really appreciate it. 
  Thanks a lot for your time and consideration! </p>