Whenever I run the project on the emulator, it gives me the error App keeps stopping and I can’t run the app. There was no error when debugging the code. So I checked on the Logcat then it gives me the error java.lang.RuntimeException. I have no idea where the error is or is it a problem of the code at all? Please someone help me…
-
Main Activity code
class MainActivity1 : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val circularProgressBar: CircularProgressBar = findViewById(R.id.circularProgressBar) circularProgressBar.setProgressWithAnimation(65f,1000) findViewById<SeekBar>(R.id.seekBarProgress).onProgressChanged{ circularProgressBar.progress = it } } private fun SeekBar.onProgressChanged(onProgressChanged: (Float)-> Unit){ setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress : Int, fromUser: Boolean) { onProgressChanged(progress.toFloat()) } override fun onStartTrackingTouch(seekBar: SeekBar?) { } override fun onStopTrackingTouch(seekBar: SeekBar?) { } }) }
}
-
Logcat
Image of the Logcat
2
Answers
This is my main activity xml file. (I don't know if this helps)
You’re calling
setProgressWithAnimation
on a null object. I suggest you not usefindViewById
. Use ViewBinding or at least kotlinx.