skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    This is my main activity xml file. (I don't know if this helps)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.anadroid.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity1"
        android:background="@color/white"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@drawable/bg_header"
            android:orientation="horizontal"
            android:layout_marginBottom="20dp"
            >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fontFamily="@font/poppins_semibold"
                android:text="AkiKomi"
                android:gravity="center_horizontal"
                android:layout_marginStart="15dp"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:textSize="25sp"/>
    
        </LinearLayout>
    
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/my_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search