-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

sena yun
  • 3
  • 1
  • 2

2 Answers2

1

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

Maede Jalali
  • 306
  • 2
  • 6
  • 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 '21 at 02:18
  • Would you please give me your main activity XML file? Or you can check [this](https://stackoverflow.com/questions/3264610/findviewbyid-returns-null) question as well. Btw in you can read about viewBinding [here](https://developer.android.com/topic/libraries/view-binding) – Maede Jalali Dec 14 '21 at 06: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>
sena yun
  • 3
  • 1
  • 2