Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

setonclicklistener but can't get the function to run correctly, multiple layouts

I am setting up my app, and I have gotten "onclick=" to work when I just had 1 layout, however I am now using a layout for small, normal and large now and that made my button stop working. I have my button identifying setonclicklistener however when I click the button on the app it will give me unfortunate error, and than go to a new empty page (assuming activity2), and give me another unfortunate error. I am wondering if I need to specify in the function to go to a specific layout type? even though it's going into the mainactivity.kt

my mainactivity.kt:

  package com.example.troubleshootonly.americanharvest

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.example.troubleshootonly.americanharvest.R.layout.activity_main
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(activity_main)

        button2.setOnClickListener{
            startActivity(Intent(this, Activity2::class.java))
        }
    }
    fun flowerpage(view: View){
        startActivity(Intent(this, Activity2::class.java))
    }
}

Comments