My App Keeps o Stopping and there is an exception there [closed]


I Have Tried To Rebuild the project but nothing Happened

My Code Is Down

`

        save_time.setOnClickListener {         val medicine = medicinea.text.toString()          val days = arrayOf("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")         for (aday in days) {            if(day_selected.toString() == aday) {               val shrd = getSharedPreferences("Add$  day_selected", Context.MODE_PRIVATE)               val editor = shrd.edit()               editor.putString("medicine", medicine)               editor.putString("day", day_selected)               editor.putString("whenSelected", when_selected)               editor.putString("medicineSelected", medicine_selected)               editor.putString("time", time_selected)               editor.apply()               Toast.makeText(this@Add, "Saved To Internal Database", Toast.LENGTH_SHORT).show()           }       }            if (day_selected.toString() == "Friday") {             val intent = Intent(this, Friday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)           }          if (day_selected.toString() == "Saturday") {             val intent = Intent(this, Saturday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)  }         if (day_selected.toString() == "Sunday") {             val intent = Intent(this, Sunday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)          }         if (day_selected.toString() == "Monday") {             val intent = Intent(this, Monday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)         }          if (day_selected.toString() == "Tuesday") {             val intent = Intent(this, Tuesday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)         }         if (day_selected.toString() == "Wednesday") {             val intent = Intent(this, Wednesday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)         }         if (day_selected.toString() == "Thursday") {             val intent = Intent(this, Thursday::class.java)             CustomIntent.customType(this@Add, "fadein-to-fadeout")             startActivity(intent)         }      }` 

From here if i go to Friday activity

 package com.example.medicaltimetableapp   import android.content.Context  import com.example.medicaltimetableapp.R  import android.graphics.Color  import android.os.Build  import android.os.Bundle  import android.view.View  import android.widget.TextView  import androidx.annotation.RequiresApi  import androidx.appcompat.app.AppCompatActivity  import androidx.constraintlayout.widget.ConstraintSet  import kotlinx.android.synthetic.main.activity_add.*  import kotlinx.android.synthetic.main.activity_friday.*  import kotlinx.android.synthetic.main.activity_main.view.*   class Friday : AppCompatActivity() {  @RequiresApi(Build.VERSION_CODES.LOLLIPOP) override fun onCreate(savedInstanceState: Bundle?) {     super.onCreate(savedInstanceState)     setContentView(R.layout.activity_friday)        val pref = getSharedPreferences("AddFriday", MODE_PRIVATE)     val dayA = pref?.getString("day", "NOT FOUND ").toString()     val medicinea = pref?.getString("medicine", "NOT FOUND ").toString()     val whenSel = pref?.getString("whenSelected", "NOT FOUND ").toString()     val mediselec = pref?.getString("medicineSelected", "NOT FOUND ").toString()     val time = pref?.getString("time", "NOT FOUND ").toString()      val layout = fridaylayout      val dayview = add_view(dayA, R.id.dayf)     val constraintSet = ConstraintSet().apply {         clone(layout)         connect(R.id.dayf, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)         connect(R.id.dayf, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT)     }     constraintSet.applyTo(layout)      val medicineview = add_view(medicinea, R.id.medicinef)     medicineview!!.x = +100F     val constraintSet1 = ConstraintSet().apply {         clone(layout)         connect(R.id.medicinef, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)         connect(R.id.medicinef, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT)     }     constraintSet.applyTo(layout)      val whenselview = add_view(whenSel, R.id.whenf)     whenselview!!.x = +200F     val constraintSet2 = ConstraintSet().apply {         clone(layout)         connect(R.id.whenf, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)         connect(R.id.whenf, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT)     }     constraintSet.applyTo(layout)      val mediselview = add_view(whenSel, R.id.howmuchf)     mediselview!!.x = +300F     val constraintSet3 = ConstraintSet().apply {         clone(layout)         connect(R.id.howmuchf, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)         connect(R.id.howmuchf, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT)     }     constraintSet.applyTo(layout)      val timeview = add_view(whenSel, R.id.timef)     timeview!!.x = +400F     val constraintSet4 = ConstraintSet().apply {         clone(layout)         connect(R.id.timef, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)         connect(R.id.timef, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT)     }     constraintSet.applyTo(layout)      layout.addView(dayview)     layout.addView(medicineview)     layout.addView(whenselview)     layout.addView(mediselview)     layout.addView(timeview)    }   private fun add_view(data: String, id: Int): View? {      val text = TextView(applicationContext)     text.setBackgroundColor(Color.rgb(255, 229, 229))     text.width = 100     text.height = 50     text.x = 21F     text.y = 88F     text.id = id     text.text = data      return text } 

}

And I Get This Exception

E/AndroidRuntime: FATAL EXCEPTION: main     Process: com.example.medicaltimetableapp, PID: 24254    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.medicaltimetableapp/com.example.medicaltimetableapp.Tuesday}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.constraintlayout.widget.ConstraintLayout.addView(android.view.View)' on a null object reference         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)       at android.app.ActivityThread.-wrap11(Unknown Source:0)       at android.app.ActivityThread$  H.handleMessage(ActivityThread.java:1613)      at android.os.Handler.dispatchMessage(Handler.java:106)        at android.os.Looper.loop(Looper.java:164)        at android.app.ActivityThread.main(ActivityThread.java:6523)       at java.lang.reflect.Method.invoke(Native Method)       at com.android.internal.os.RuntimeInit$  MethodAndArgsCaller.run(RuntimeInit.java:438)       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.constraintlayout.widget.ConstraintLayout.addView(android.view.View)' on a null object reference     at com.example.medicaltimetableapp.Tuesday.onCreate(Tuesday.kt:44)          at android.app.Activity.performCreate(Activity.java:7023)     at android.app.Activity.performCreate(Activity.java:7014)     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)      at android.app.ActivityThread.-wrap11(Unknown Source:0)      at android.app.ActivityThread$  H.handleMessage(ActivityThread.java:1613)      at android.os.Handler.dispatchMessage(Handler.java:106)      at android.os.Looper.loop(Looper.java:164)      at android.app.ActivityThread.main(ActivityThread.java:6523)      at java.lang.reflect.Method.invoke(Native Method)      at com.android.internal.os.RuntimeInit$  MethodAndArgsCaller.run(RuntimeInit.java:438)      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)  

My Manifiest File

<?xml version="1.0" encoding="utf-8"?> 

<application     android:allowBackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:roundIcon="@mipmap/ic_launcher_round"     android:supportsRtl="true"     android:theme="@style/AppTheme">     <activity android:name=".MainActivity"></activity>     <activity android:name=".Add"></activity>     <activity android:name=".Sunday" />     <activity android:name=".Saturday" />     <activity android:name=".Friday" />     <activity android:name=".Thursday" />     <activity android:name=".Wednesday" />     <activity android:name=".Tuesday" />     <activity android:name=".Monday" />     <activity android:name=".homeanimation">         <intent-filter>             <action android:name="android.intent.action.MAIN" />              <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>     </activity> </application> 

Can Anyone Please Help Me

Thanks Asad