-1

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 2

1

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

2
  • Thank you for the help. I'm new to this app developing and trying to understand how this works. So may I ask you to explain in more details?
    – sena yun
    Dec 14, 2021 at 2:18
  • Would you please give me your main activity XML file? Or you can check this question as well. Btw in you can read about viewBinding here Dec 14, 2021 at 6:52
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.