• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method Return Issue

 
Greenhorn
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have an issue trying to return the result from the method below and I am hoping that somebody might be able to spare a little time to assist me.

I have a standard pojo Customer class with three instance variables, constructors, setters and getters



I have created a vector called CustomerVector and populated it with customers.
I want to iterate through the vector to find the customer object that has the same customerId as the int that is passed into the method.



However when I try to return the result the return statement can not see the result String.

Any help to get around this issue would be greatly appreciated

Thanks in advance
Nigel
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your String result is declared inside your if-statement body. When you exit that block on line 7, it goes out of scope and is therefore not available. simply declare it outside the loop:

 
Nigel Foley
Greenhorn
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fred,

Thank you very much for the quick accurate response I really apprecriate it,
my issue is now resolved and the method is returning the customer name :-)

Nigel
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic