Намеренная ошибка: java .lang.IllegalStateException: findViewById (R.id.image_resep) не должно быть нулевым - PullRequest
0 голосов
/ 30 апреля 2020

я получил ошибку для своего кода. когда я открываю это cra sh

, это мой код в DetailResep.kt

class DetailResep : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.list_resep)

    val tvNama: TextView = findViewById(R.id.tv_item_name)

    val name = intent.getStringExtra(NAME)
    val detail = intent.getStringExtra(DETAIL)

    tvNama.text = name

    //my problem code
    val imageView: ImageView = findViewById(R.id.image_resep)
    val image = intent.getIntExtra(IMAGE, R.drawable.tumis_buncis)
    imageView.setImageResource(image)
}

companion object {
    const val DETAIL = "detail"
    const val NAME = "name"
    const val IMAGE = "image"
}

}

, тогда это мой код xml. Я хочу изменить изображение в id.image_resep

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/detail_resep"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

        <ImageView
            android:id="@+id/image_resep"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/ayam_teriyaki"/>

       <TextView
            android:id="@+id/tv_item_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/frm_img"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="#00CC00"
            android:text="@string/resep_name" />

, когда я открываю это xml я получил код ошибки. затем я проверяю java .lang.IllegalStateException: findViewById (R.id.image_resep) не должен быть нулевым

...