jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Keep getting String error in my JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Keep getting String error in my JSP page" Watch "Keep getting String error in my JSP page" New topic
Author

Keep getting String error in my JSP page

Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
here is the code


I keep getting an error that says I must return a string. what am I doing wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

Your return statement is inside the for loop body. Not only does this mean that the loop can execute only once, but if the loop were to never execute there's no return statement for the method, and that's what the compiler is complaining about.

So, why is the return in the for body? Just a placement error?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I guess the return is misplaced. Do you really want it there?
Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
i took the return statement out of the for loop and it still only returned hi once
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Only one thing will be returned from the method. Once you call the return statement, the method will exit.

To accomplish what you're trying to do I would suggest creating a local variable of type String and concatenate into it the String "hi" as many times as you need.

Then you can return that String.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 819
There's no concatenation, just assignment.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Keep getting String error in my JSP page