• Post Reply Bookmark Topic Watch Topic
  • New Topic

for loop not converting each id to a name...  RSS feed

 
jason thompson
Greenhorn
Posts: 9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code that returns a bunch of IDs as a String type. Then I separate each ID from the String and pass them to another method to convert it to a name. But only the first ID gets converted while the rest remains as is.

An example of units would be (the number of ID could be different):




This still only converts the first ID to a unit name. Unit names might look like this:



instead I am seeing:



How do I get every ID as a unit name?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well...you didn't provide code I can compile and test myself, so that makes it a little harder to help you.

What I'd suggest you do is throw in a bunch of print statements and make sure every string and array you build REALLY contains what you think it contains. Make sure the length of units three is actually what you think it should be.

Somewhere, you'll find something isn't doing what you think it is....then you need to figure out why. And that's where println can be your best friend.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jason thompson wrote:This still only converts the first ID to a unit name.

  • First:: +1 for an intelligent question, plainly with some thought put in to what the problem might be.
  • However: −1 for not thinking about what we may need to answer you question. Most of us have a fair bit of experience, but we're not psychic.
  • OTOH: +1 for providing us with input and output, which allows us to to make some guesses about what the problem might be - but you understand, they are simply guesses.
  • So, overall: +1 (but could have been +3 == 1 cow ).

    OK, now to your problem:
    It appears to revolve around UnitRepository.getUnitName(), which takes and returns a String - presumably a conversion to a format that you intend to use somewhere else - and if it CAN'T convert, it returns the original String unchanged.

    So: the answer is (or would appear to be) simple: UnitRepository.getUnitName() can't convert the second (and third...) Strings you're passing to it.

    But WHY it can't, we have no idea; because we don't have enough information.

    But I have a suggestion: Concentrate on one problem to start with:
    Why can't it convert
      56e12fc4-97b3-44e7-b59a-5df0267424ac
    to
      unit-two
    ?

    I suspect that when you work that out, you'll solve the rest.

    HIH

    Winston
     
    jason thompson
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am always a little disappointed when I post here. Everyone always wants me to post my entire source to figure out my problem, yet nothing else is relevant. I tested all the other components individually.

    I will say there was at least some good advice here:

    But I have a suggestion: Concentrate on one problem to start with:
    Why can't it convert
    56e12fc4-97b3-44e7-b59a-5df0267424ac
    to
    unit-two
    ?

    I suspect that when you work that out, you'll solve the rest.


    That is how I figured out my problem. Adding fixes it.





    Thanks Winston
     
    Knute Snortum
    Sheriff
    Posts: 4091
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    An alternative:

    or even better:
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!