Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

help with following error: java:32: unreachable statement

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i keep getting this error( java:32: unreachable statement) within my class and i dont see why i am getting it.

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method "getPill()" is set up to return a String. Fine. But look at this code snippet:

You can't have any executable code immediately following a "return ..." statement because there is no way the code can reach that point, which is what the compiler is explaining.
There are a couple of ways of correcting this. You can us an "if/else if/else" construct. Or you can set the med type within the "switch()" construct and remove the "return" statements, placing one return at the end of the method.
Also, it looks like you're trying to return multiple pills in some cases. But the method says it return a single String. If you want to return multiple values, you'll need to use and Array or ArrayList or some other collection.
Give it a try and post again if you run into additional problems.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume the message actually said something like

Meds.java:32: unreachable statement
The first part indicates that the problem is in the file Meds.java, line 32. Find that line number to get a better idea what the problem is.
 
machines help you to do more, but experience less. Experience this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic