• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keep getting String error in my JSP page

 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the return is misplaced. Do you really want it there?
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i took the return statement out of the for loop and it still only returned hi once
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no concatenation, just assignment.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic