Results 1 to 7 of 7
- 03-11-2009, 11:52 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
Unreachable Statement (accessors) - works as a main method!
I've got this to turn the length of a music track into seconds, it works fine as a main methods (as below):
However, I'm putting it in my accessor method like this, and I'm getting an "Unreachable Statement" on the variable trackLengthToSecs.
Last edited by thomase; 03-12-2009 at 12:50 PM. Reason: removing private code
-
Please repost the entire class reformatted. Good luck.
- 03-11-2009, 02:22 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
-
What in the trackDetails() method will be called after this statement has been reached?
Java Code:return trackName + "|" + trackLenght;
- 03-11-2009, 04:25 PM #5
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Is there a reason you use the name trackLenght, spelled incorrectly, while you use trackLengthToSecs, spelled correctly, or you're just too lazy to change it? ;)
Your error is here
After you've returned (a value), it stops with that method, so you can't put anything after that.Java Code:return trackName + "|" + trackLenght; //Gets total minutes int secInt1 = (int) trackLengthToSecs; // Etc.
Btw.. why don't you just use this?
Java Code:public int toSeconds(final double time) { return (int)(time)*60+(int)((time-mins)*100); }I die a little on the inside...
Every time I get shot.
- 03-11-2009, 04:32 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
Supamagier, the amount of times i've spelt leng, lenth, length!!, wrong during this one little bit of java coding is amazing :P I now don't care how it's spelt, as long as it works :p.
Thanks for pointing out the above return is stopping it from working - I should of really realised that, I just thought it'd be more complicated :P.
That would possibly make more sense :P. The reason it was longer was because it took me a little while to work out how I wanted to do it so did it in a few stages - think I'll leave it like that for now (cheers for the better method though - made me actually think about shrinking stuff down after I've done it!!).
Also, I might copy the public int toSeconds(final double time) { bit. The question mentions using a toString method - is what you've got a to string, or am I reading too much into the to in front of seconds :P
- 03-11-2009, 04:38 PM #7
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
It's spelled length ;)
Yea, you should ^^ beginner mistake. xD
You're welcome m8
Go ahead.
To return a String, just change public int into public String and change return blabla to return String.valueOf(blabla). :)I die a little on the inside...
Every time I get shot.
Similar Threads
-
Basic Circular Linked List - addFirst() method works improperly
By carlodelmundo in forum New To JavaReplies: 9Last Post: 11-04-2011, 03:09 AM -
Using accessors properly
By LifeWithJava in forum New To JavaReplies: 2Last Post: 12-23-2008, 02:49 PM -
unreachable statement - Java calculator program
By V2001Gordon in forum New To JavaReplies: 3Last Post: 12-13-2008, 12:57 AM -
how compareTo Method works
By nanaji in forum Advanced JavaReplies: 1Last Post: 06-22-2008, 07:40 PM -
Method in a Switch Statement
By cart1443 in forum New To JavaReplies: 6Last Post: 03-14-2008, 03:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks