• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with following error: java:32: unreachable statement  RSS feed

 
Sally Curtis
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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.

 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • 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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!