When I wrote the following code, I got an error on the second line.

val imageCapture = ImageCapture (imageCaptureConfig)
        findViewById (R.id.capture_button) .setOnClickListener {<<<<<<<<<<<<<<<<<<Error
        val file = File (externalMediaDirs.first (),
                "${System.currentTimeMillis ()}. Jpg")
            imageCapture.takePicture (file, executor,
                object: ImageCapture.OnImageSavedListener {
                    override fun onError (
                        imageCaptureError: ImageCapture.ImageCaptureError,

The details of the error are as follows.

Type inference failed: Not enough information to infer parameter T in fun<T: View!>findViewById (p0: Int): T!
Please specify it explicitly.</Code></pre>
<p>When I looked into it, the description method for KOTLIN seemed to be different</p>
<p>Reference URL<br />
<p>Because the code has been written again like this</p>
<pre><code>val root = inflater.inflate (R.layout.fragment_camera, container, false)
        val textView: TextView = root.findViewById (R.id.text_camera)

I tried the following, but it didn't work.

Error source

findViewById (R.id.capture_button) .setOnClickListener {<<<<<<<<<<<<<<<<<<<<<<Error

The source I tried this time

root.findViewById (R.id.capture_button) .setOnClickListener {<<<<<<<<<<<<<<<<<<<<
<p>This is another source I tried this time.</p>
<pre><code>root.findViewById<Root>(R.id.capture_button) .setOnClickListener {<<<<<<<<<<<<<<<<<&<<</Try>

How can I get an error? We apologize for the trouble.

  • Answer # 1

    Please specify the cast type explicitly.

    root.findViewById(R.id.capture_button) .setOnClickListener {...}

Related articles