I am doing a quiz app in android studio and this setContentView(R.layout.activity_acknowledgement line from my acknowledge activity keeps crashing my project and keeps showing "the app has stopped " while running.
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_acknowledgement.*
class AcknowledgementActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_acknowledgement)
btn_learn.setOnClickListener{
if(et_name.text.toString().isEmpty()) {
Toast.makeText(this, "Please enter your name", Toast.LENGTH_SHORT).show()
}else{
val intent = Intent (this@AcknowledgementActivity, DashboardActivity::class.java)
startActivity(intent)
finish()
}
}
}
}
Logcat says that the problem is on setcontentView line. This is my logcat
at com.example.wisdomtree.AcknowledgementActivity.onCreate(AcknowledgementActivity.kt:14)
and this is my xml file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AcknowledgementActivity"
android:background="@drawable/acknwlgemnt"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/tv_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="420dp"
android:fontFamily="@font/amaranth"
android:gravity="center"
android:text="Welcome"
android:textColor="#363A43"
android:textSize="30sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="500dp"
android:text="Please enter your name"
android:textColor="#7A8089"
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="540dp"
android:layout_marginLeft="50dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
>
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_name"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Name"
android:textColor="#363A43"
android:textColorHint="#7A8089"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btn_learn"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="620dp"
android:background="#43A047"
android:fontFamily="@font/chewy"
android:text="Start Learning"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="18sp">
</Button>
</RelativeLayout>
This line xmlns:app="http://schemas.android.com/apk/res-auto" from xml file and this line import android.view.View from activity keeps turning grey and I don't know what to do.