• Post Reply Bookmark Topic Watch Topic
  • New Topic

No compiling errors, but println isn't working  RSS feed

 
Alex Jung
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what's going on with this, but I cannot get this to work.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

People here will be happy to help you, but we need you to do your part. Two key points here:

1) ItDoesntWorkIsUseless.(⇐click) We need details.

2) UseCodeTags.(⇐click) It makes your code easier to read.
 
Alex Jung
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that. there are no compiling errors, but Line 21 isn't displaying anything when I run this.

 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you should put e.printStackTrace() inside the catch block.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is throwing exception and most probably java.io.FileNotFoundException
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your line 29:

If an exception happens, you catch the exception and ignore it. That way you'll never know if something went wrong. Never ignore exceptions. At least print an error message. For example:
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Look at your line 29:

If an exception happens, you catch the exception and ignore it. That way you'll never know if something went wrong.


And just as importantly, neither will your code. The rest of it will go on thinking everything is fine, when it's not. It's like you're driving your car, and somebody is yelling at you that you have a flat tire, so you close the window because the noise is bothering you.

Even printing the stacktrace isn't by itself a generally valid way to deal with an exception. You need to either fix what went wrong, or throw something. But for an academic context, just printing the stack trace is often sufficient.
 
Alex Jung
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help. My teacher told my class to just put that in the code and simply said we need it to work and that he'd explain it later. Now I see what I needed to fix and it works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!