skip to Main Content

MainActivity.kt
PutExtra(String!.String?) is givng error (in android Kotlin), what could be the problem?

class MainActivity : AppCompatActivity() 

{
    override fun onCreate(savedInstanceState: Bundle?)

{
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)


}
    var name:EditText? = null


fun createBirthdayCard(view: View) {

    name = findViewById(R.id.NameInput)
    val intent = Intent(this,BirthdayGreetActivity::class.java)
    intent.putExtra(BirthdayGreetActivity.NAME_EXTRA,name)
    startActivity(intent)

}

}

2

Answers


  1. when sending data

    intent.putExtra("name",name)
    

    when receiving data

    val name= intent.getStringExtra("name").toString()
    
    Login or Signup to reply.
  2. intent.putExtra(BirthdayGreetActivity.NAME_EXTRA,name)
    

    this line of yours adds NameInput to intent not string. I dont know what your NameInput is but you may try name.text. Maybe if you gave the code of NameInput I might help better.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search