• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error - For loop,loops round twice  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It currently prints out the directory and the classes in a package but it does it twice and debugging it it never hits return - is there anything that can be done to improve it? I don't get why it loops through twice and then goes on to execute the other code :s

 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of System.getProperty("java.class.path")?
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It returns the classpath it currently resides on - C:\Users\fk\git\Merlin

*Edit

Rather than have the code in the else as that method currently has nothing in it. It was going through a jar file when I debugged when it hit that method I noticed so I changed it to else return and it only retrieves the values once now.
 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post some more code?
For example methods findClassesInDirectory and findClassesInArchive and the method containing your loop?
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code below works just fine so I suspect something in your method calls is the problem.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alice Hampton wrote:It currently prints out the directory and the classes in a package but it does it twice and debugging it it never hits return - is there anything that can be done to improve it? I don't get why it loops through twice and then goes on to execute the other code :s

And without knowing what findClassesInDirectory() and findClassesInArchive() do, neither do we.

However, you could help yourself out by breaking up some of that logic so that you can track it, viz:I'm sure you get the idea.

Winston
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers guys!

It was my method that was causing the issue - I basically did what Knute did in the if else (only just seen your answer now Knute)

Yes Winston I have done - thank you for the advice! I can be a bit messy when I code I should really tidy as I go!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alice Hampton wrote:I basically did what Knute did in the if else...

It's purely my preference, but I tend not to like negative logic, so I think I might have written:but there's no "right" or "wrong" about it.

Winston
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree Winston - how you wrote it is how I normally write it actually I've just ended up re-writing it as I've been messing on changing that much of it
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW Alice, this thread looks very similar to this one. Have you finished with the other one? If so, could you mark it as "resolved"?

Thanks.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!