Android: variable has incorrect value in while loop Android: variable has incorrect value in while loop android android

Android: variable has incorrect value in while loop


If you are really sure that the written code works correctly then from now on, you must start to check (ordered):

  • configuration --> is your project configuration totally ok with Java versions, jdks or the Java version is compatible with used Android libraries? Are your Java and Andorid libraries correctly configured?
  • environment --> is your debugging emulator a 3rd party library or is your debugging device is a valid device to debug your code? Is your coding OS is compatible with your ide, Java version or Android libraries?
  • JVM --> Did you try uninstalling and reinstalling with the correct source for Java jdk with the version you are using?

Maybe you must give some details about your environment like Java version, Android min version, OS or the IDE you are using.

I hope those bullets will make you some correct associations to resolve your problem.


I cannot reproduce the example. I am getting always (both run and debug configurations):

value before = 23value in while loop = 23

I just created a new project in my Android Studio and compiled it using the SDK version 28. Then I just ran the project in the emulator (with API 26) and everything worked as expected.