title: Kotlin Fragment : Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
body: <p>I use Intent.ACTION_PICK to take picture from gallery.
  I already success when implement both activity, but found problem when using fragment.
  I need some help, please.</p>
  <p>Here MainActivity.kt</p>
  <pre><code>    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
          if (resultCode == Activity.RESULT_OK) {
              when (requestCode) {
                  REQUEST_NEW_CHAT -&gt; {
                      val name: String = data?.getStringExtra(PARAM_NAME) ?: &quot;&quot;
                      val phone: String = data?.getStringExtra(PARAM_PHONE) ?: &quot;&quot;
                      checkNewChatUser(name, phone)
                  }
                  //TODO: I.5. Update Status Page
                  REQUEST_CODE_PHOTO -&gt; statusUpdateFragment?.storeImage(data?.data)
              }
          }
      }
  </code></pre>
  <p>Here StatusUpdateFragment.kt</p>
  <pre><code>    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          lay_progressbar.setOnTouchListener { v, event -&gt; true }
          btn_status.setOnClickListener { onUpdate() }
          populateImage(context, imageUrl, img_status)
  
          lay_status.setOnClickListener{
              if(isAdded){
                  (activity as MainActivity).startNewActivity(REQUEST_CODE_PHOTO)
              }
          }
      }
  
      fun storeImage(imageUri: Uri?) {
          if (imageUri != null &amp;&amp; userId != null) {
              //error message : Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
              try {
                      Toast.makeText(activity, &quot;Uploading...&quot;, Toast.LENGTH_SHORT).show()
                      lay_progressbar.visibility = View.VISIBLE
              }
              catch (e:Exception){
                  e.message
              }
  
              /*more code that i hide it...*/
          }
      }
  </code></pre>