title: "Type mismatch: inferred type is Fragment but Context was expected" and "None of the following functions can be called with the arguments supplied:"
body: <pre><code>package com.example.mobilewarehousesystem.ui.import
  
  import android.Manifest
  import android.content.DialogInterface
  import android.content.Intent
  import android.content.pm.PackageManager
  import android.graphics.Bitmap
  import android.os.Bundle
  import android.provider.MediaStore
  import android.util.Log
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.Toast
  import androidx.activity.result.ActivityResult
  import androidx.activity.result.ActivityResultCallback
  import androidx.activity.result.ActivityResultLauncher
  import androidx.activity.result.contract.ActivityResultContracts
  import androidx.core.app.ActivityCompat
  import androidx.core.content.ContextCompat
  import androidx.fragment.app.Fragment
  import com.example.mobilewarehousesystem.databinding.FragmentImportBinding
  import com.google.mlkit.vision.barcode.Barcode
  import com.google.mlkit.vision.barcode.BarcodeScanner
  import com.google.mlkit.vision.common.InputImage
  import androidx.appcompat.app.AlertDialog
  
  class ImportFragment : Fragment() {
      //show UI
      private var _binding: FragmentImportBinding?=null
      private val binding get() = _binding!!
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
          _binding = FragmentImportBinding.inflate(inflater, container, false)
          setHasOptionsMenu(true)
          return binding.root
      }
  
      private val CAMERA_PERMISSION_CODE=123
      private val READ_STORAGE_PERMISSION_CODE=113
      private val WRITE_STORAGE_PERMISSION_CODE=113
      private lateinit var cameraLauncher: ActivityResultLauncher&lt;Intent&gt;
      private lateinit var galleryLauncher: ActivityResultLauncher&lt;Intent&gt;
      private val TAG = &quot;My Tag&quot;
      lateinit var inputImage: InputImage
      lateinit var barcodeScanner: BarcodeScanner
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          cameraLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult(), object :ActivityResultCallback&lt;ActivityResult&gt;{
              override fun onActivityResult(result: ActivityResult?) {
                      val data=result?.data
                      try{
                          val photo = data?.extras?.get(&quot;data&quot;) as Bitmap
                          inputImage= InputImage.fromBitmap(photo, 0)
                          processQr()
                      }catch(e:Exception){
                          Log.d(TAG, &quot;onActivityResult:&quot;+e.message)
                      }
                  }
              })
          galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult(), object :ActivityResultCallback&lt;ActivityResult&gt;{
                  override fun onActivityResult(result: ActivityResult?) {
                      val data=result?.data
                      inputImage = InputImage.fromFilePath(this@ImportFragment, data?.data)
                      processQr()
                  }
              })
          binding.btnScanBarcode.setOnClickListener{
              val options=arrayOf(&quot;camera&quot;,&quot;gallery&quot;)
  
              val builder=AlertDialog.Builder(this@ImportFragment)
              builder.setTitle(&quot;Pick a option&quot;)
  
              builder.setItems(options, DialogInterface.OnClickListener { dialog, which -&gt;
                  if(which==0){
                      val cameraIntent=Intent(MediaStore.ACTION_IMAGE_CAPTURE)
                      cameraLauncher.launch(cameraIntent)
                  }else{
                      val storageIntent=Intent()
                      storageIntent.setType(&quot;image/*&quot;)
                      storageIntent.setAction(Intent.ACTION_GET_CONTENT)
                      galleryLauncher.launch(storageIntent)
                  }
              })
              builder.show()
          }
      }
      private fun processQr(){
          binding.ivQrCode.visibility=View.GONE
          binding.tvResult.visibility=View.GONE
          barcodeScanner.process(inputImage).addOnSuccessListener{
              for (barcode:Barcode in it){
                  val valueType=barcode.valueType
                  when (valueType) {
                      Barcode.TYPE_WIFI -&gt; {
                          val ssid = barcode.wifi!!.ssid
                          val password = barcode.wifi!!.password
                          val type = barcode.wifi!!.encryptionType
                          binding.tvResult.text = &quot;ssid ${ssid} \n password ${password} \n type ${type}&quot;
                      }
                      Barcode.TYPE_URL -&gt; {
                          val title = barcode.url!!.title
                          val url = barcode.url!!.url
                          binding.tvResult.text = &quot;title ${title} \n url ${url}&quot;
                      }
                      Barcode.TYPE_TEXT-&gt;{
                          val data = barcode.displayValue
                          binding.tvResult.text=&quot;Result ${data}&quot;
                      }
                  }
              }
          }.addOnFailureListener{
              Log.d(TAG, &quot;processQr: ${it.message}&quot;)
          }
      }
      override fun onResume() {
          super.onResume()
          checkPermission(Manifest.permission.CAMERA,CAMERA_PERMISSION_CODE)
      }
      private fun checkPermission(permission:String, requestCode:Int){
          if(ContextCompat.checkSelfPermission(this@ImportFragment, permission)== PackageManager.PERMISSION_DENIED){
              ActivityCompat.requestPermissions(this@ImportFragment, arrayOf(permission),requestCode)
          }
      }
      override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;out String&gt;, grantResults: IntArray) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults)
  
          if(requestCode==CAMERA_PERMISSION_CODE){
              if(grantResults.isNotEmpty() &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED){
                  checkPermission(
                      android.Manifest.permission.READ_EXTERNAL_STORAGE,
                      READ_STORAGE_PERMISSION_CODE)
              }else{
                  Toast.makeText(this@ImportFragment, &quot;Camera Permission Denied&quot;, Toast.LENGTH_SHORT).show()
              }
          }else if(requestCode==READ_STORAGE_PERMISSION_CODE){
              if((grantResults.isNotEmpty() &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)){
                  checkPermission(
                      android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
                      WRITE_STORAGE_PERMISSION_CODE)
              }else{
                  Toast.makeText(this@ImportFragment, &quot;Storage Permission Denied&quot;, Toast.LENGTH_SHORT).show()
              }
          }else if(requestCode==WRITE_STORAGE_PERMISSION_CODE) {
              if (!(grantResults.isNotEmpty() &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                  Toast.makeText(this@ImportFragment, &quot;Storage Permission Denied&quot;, Toast.LENGTH_SHORT).show()
              }
          }
      }
  }
  </code></pre>
  <p>I consist 7 error, it is all of them are implementation error??
  Those code were converted 1 by 1 from MainActivity into Fragment with the limited knowledge, i found some solution but still didnt know how to apply into mine.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>code</th>
  <th>error</th>
  <th>line</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td><code>inputImage = InputImage.fromFilePath(this@ImportFragment, data?.data)</code></td>
  <td>Type mismatch: inferred type is ImportFragment but Context! was expected</td>
  <td>63</td>
  </tr>
  <tr>
  <td><code>val builder=AlertDialog.Builder(this@ImportFragment)</code></td>
  <td>Type mismatch: inferred type is ImportFragment but Context! was expected</td>
  <td>70</td>
  </tr>
  <tr>
  <td><code>if(ContextCompat.checkSelfPermission(this@ImportFragment, permission)== PackageManager.PERMISSION_DENIED){</code></td>
  <td>Type mismatch: inferred type is ImportFragment but Context! was expected</td>
  <td>120</td>
  </tr>
  <tr>
  <td><code>ActivityCompat.requestPermissions(this@ImportFragment, arrayOf(permission),requestCode)</code></td>
  <td>Type mismatch: inferred type is ImportFragment but Activity was expected</td>
  <td>121</td>
  </tr>
  <tr>
  <td><code>Toast.makeText(this@ImportFragment, &quot;Camera Permission Denied&quot;, Toast.LENGTH_SHORT).show()</code></td>
  <td>None of the following functions can be called with the arguments supplied:<br/>public open fun makeText(context: Context!, text: CharSequence!, duration: Int): Toast! defined in android.widget.Toast<br/>public open fun makeText(context: Context!, resId: Int, duration: Int): Toast! defined in android.widget.Toast</td>
  <td>133</td>
  </tr>
  <tr>
  <td><code>Toast.makeText(this@ImportFragment, &quot;Storage Permission Denied&quot;, Toast.LENGTH_SHORT).show()</code></td>
  <td>None of the following functions can be called with the arguments supplied:<br/>public open fun makeText(context: Context!, text: CharSequence!, duration: Int): Toast! defined in android.widget.Toast<br/>public open fun makeText(context: Context!, resId: Int, duration: Int): Toast! defined in android.widget.Toast</td>
  <td>141, 145</td>
  </tr>
  </tbody>
  </table>
  </div>