title: How can I solve my app crash error?
body: <p>I am a new Android developer, and I just released my first app but I am getting app crash reports.</p>
  
  <p>This is the problem I am getting. As far as I can understand, it's saying the error generates on the 69 line of my fragment class. </p>
  
  <pre><code> Exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
   android.content.ComponentName.&lt;init&gt; (ComponentName.java:77)
   android.content.Intent.&lt;init&gt; (Intent.java:4913)
   com.botmad.questionme.AnswerFragmentOne.refresh (AnswerFragmentOne.java:69)
   com.botmad.questionme.AnswerFragmentOne$1.run (AnswerFragmentOne.java:60)
   android.os.Handler.handleCallback (Handler.java:739)
   android.os.Handler.dispatchMessage (Handler.java:95)
   android.os.Looper.loop (Looper.java:145)
   android.app.ActivityThread.main (ActivityThread.java:6946)
   java.lang.reflect.Method.invoke (Method.java)
   java.lang.reflect.Method.invoke (Method.java:372)
   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
   com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
  </code></pre>
  
  <p>And here is my fragmentOne code</p>
  
  <pre><code> public void refresh(){
      this.startActivity(new Intent(getContext(), PlayActivity.class));
      actvty.overridePendingTransition(0,0);
      actvty.finish();
  }
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
  
      actvty = (Activity)context;
  }
  
  @Override
  public void onClick(View v){
  
      final PlayActivity actvty = (PlayActivity) getActivity();
      actvty.soundeffect(1);
      final Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
          @Override
          public void run() {
              refresh();
          }
      }, 4000);
  }
  </code></pre>
  
  <p>The refresh function's first line is the 69 line. So that's where the error generates but I am not sure why orhow to solve this problem? I am restarting my main activity from this fragment. There is pretty much nothing else in the fragment class. Just a button that calls this refresh function on onClick.</p>