Skip to content Skip to sidebar Skip to footer

Not Supplying Enough Data To Hal, Expected Position

I'm getting this error in Android Studio. I just want to print the text when I push the button. I get the below error, which appears every time I press the button. If I uncomment o

Solution 1:

XML are fine but the main activity class is not using kotlin in the right way, in order to bind your items from your layout you can use synthetic native library like this

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.* // this imports all your items from your layoutclassMainActivity : AppCompatActivity() {

    overridefunonCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val searchEditText = searchEditText.text.toString() 
        // you can now use any items in the layout just by calling them

        searchButton.setOnClickListener{
            println(searchEditText)
        }

    }
}

Hope it helps

Solution 2:

Change you class code to this

val editText = findViewById<EditText>(R.id.searchEditText)
    val searchEditText = editText.text.toString()


    val button = findViewById<Button>(R.id.searchButton)
    button.setOnClickListener {
        println(searchEditText)
        //val intent = Intent(this,SearchResultActivity::class.java)//intent.putExtra("searchTerm",searchEditText)//startActivity(intent)overridefunonCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

    }
  }

Here we have just moved the "override" statement to the very end. I faced a similar issue but in Java, and when I moved the override function to the bottom, I didn't see that issue anymore. I hope it works for Kotlin as well.

Post a Comment for "Not Supplying Enough Data To Hal, Expected Position"