Search code examples
androidandroid-studiokotlinandroid-emulatorruntimeexception

"App keeps stopping" pop ups and give the error java.lang.RuntimeExcpetion


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...

  1. 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?) {
    
             }
         })
     }
    

    }

  2. Logcat Image of the Logcat


Solution

  • You're calling setProgressWithAnimation on a null object. I suggest you not use findViewById. Use ViewBinding or at least kotlinx.