• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

switch statement code being activated when the condition isn't even being met

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code being activated when it shouldn't be

I'm a beginner at android development and I can't for the life of my figure out why this is happening. Basically, I have this code:


But whenever I push the "NO" button, activating the "case R.id.NO" section of code, the code does execute but then for some reason the "case R.id.YES" section of code is also activated despite me never even pressing the YES button. I mean once I press the "NO" button, a new activity is supposed to start so it shouldn't be possible to press the YES button anyway. Why is this happening? I added some log tags within the code and I can show them here:
08-25 21:36:37.517 7267-7267/com.example.testing_load D/LOG: class com.example.testing_load.DefectEntry´╣Ľ CASE: NO
08-25 21:36:37.527 7267-7267/com.example.testing_load D/LOG: class com.example.testing_load.DefectEntry´╣Ľ CASE: YES

So according to the log tags I am pressing the YES button 0.01 of a second after I hit the NO button, but obviously this is not the case.

Here is the code for the entire class:


thanks for any help in advance.
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a read through the Java Tutorial for the Switch Statement paying particular to the function and placement of the break; statement.
 
Joshua Harris
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops I should've posted this in the android forum, my bad
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joshua Harris wrote:oops I should've posted this in the android forum, my bad


It's fine where it is. Your problem is to do with the use of the Java language and not anything to do with Android.
 
Joshua Harris
Ranch Hand
Posts: 42
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:Have a read through the Java Tutorial for the Switch Statement paying particular to the function and placement of the break; statement.



thank you. I can't believe that after like 30 mins of trying to figure this out I didn't even think to look at the documentation for switch statements.
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! Glad you got it sorted.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic