Android Studio Reinstall and restart app error

I am a new kotlin developer. On Android Studio Logcat when I add a new line of code, I get this error:

Changes were not applied. Added variable(s) does not support value initialization:
Adding static primitive 
com.kadirmetin.myapplication.LiveLiterals$MainActivityKt.Int$val-sayac$fun-onCreate$class-MainActivity
not known to be compile time constant

Reinstall and restart app

Failed to launch an application on all devices

Here is my code:


        var kullaniciIslemGunu = 5 // Pazartesi 1. gün
        var kullaniciIslemSaati = 18 // 24H

        when (kullaniciIslemGunu) {
        in 1..5 -> {
        when (kullaniciIslemSaati) {
        in 9..17 -> {
        println("İşleminiz yapılmıştır.")
        }
        in 0..8 -> {
        println("İşleminiz gün içinde saat 9:00'da gerçekleştirilecektir.")
        }
        in 18..24 -> {
        when (kullaniciIslemGunu) {
        5 -> println("İşleminiz 3 gün sonra saat 9:00'da gerçekleştirilecektir.")

        else -> println("İşleminiz yarın saat 9:00'da gerçekleştirilecektir.")
        }
        }
        }
        }
        6 -> {
        println("İşleminiz 2 gün sonra saat 9:00'da gerçekleştirilecektir.")
        }
        7 -> {
        println("İşleminiz 1 gün sonra saat 9:00'da gerçekleştirilecektir.")
        }

        else -> println("Geçerli gün giriniz.")
        }

I don’t find any suggestions. Please help =)

>Solution :

Sounds like you’re not using Run, you’re using one of the Apply Changes options

The Run and Apply Changes toolbar buttons

The one on the left is Run – it reinstalls and runs the app, so you get a completely fresh start with everything updated.

The middle one is Apply changes and Restart Activity – it basically patches the already-running app with any changes you’ve made to the code or resources, so you can see the results more quickly. It restarts the Activity, so you’ll lose any state that isn’t persisted.

The one on the right is Apply Code Changes – you can only do this if you’ve made changes to a method body, so no new top-level variables, no resource changes etc. But this one updates "live" without restarting anything, so it’s good for making code changes and seeing the results basically instantly.

Because there are limitations here, if you (say) try to do Apply Code Changes when you’ve made a change to resource files, you’ll get an error like the one you posted, "can’t apply changes". It happens in other situations too, where Apply Changes can’t handle things, and you have to do a normal Run instead (and Run always works, unless there’s something wrong with your app itself)

Leave a Reply