• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime Error ... help plz  RSS feed

 
jordan kai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

// try compile it.. got runtime error


If you can tell us what kind of runtime exception was thrown, along with a stack trace, we can give you a few pointers on how to track down the problem.

Henry
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jordan kai:



Well of course you will get a NullPointer Exception because when you call



in enterTime() method you have written the code:



Now "ans" which is a String variable is not initilized till now, and you are using equals method on a NULL Object, which in-turn throw NullPointer Exception.

I would suggest you to initialize String Object and then try to compare it as you are doing.

One more thing I can suggest you to do code like this



instead of




It will atleast not give you NullPointer Exception in any situation.
[ September 04, 2006: Message edited by: Ankur Sharma ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps You might want to write this code.

Check this Code. Now it will run according to your Expectations.



Hope this helps you out.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this helps you out.


Ankur,

While I agree that Jordan appreciates your efforts, you kinda miss the point. There is no better learning technique than figuring (parts of) it out by yourself.

If you would have just given some hints instead... then he may have figured out that with NullPointerExceptions, the stack trace provides exact line numbers and the source filename where the exception occurred.

Thanks for your efforts... just provide more hints next time...
Henry
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:


Ankur,

While I agree that Jordan appreciates your efforts, you kinda miss the point. There is no better learning technique than figuring (parts of) it out by yourself.

If you would have just given some hints instead... then he may have figured out that with NullPointerExceptions, the stack trace provides exact line numbers and the source filename where the exception occurred.

Thanks for your efforts... just provide more hints next time...
Henry


Thankx Henry,

I really appriciate your soft skills to guide me. Well I am totally agreed by you. I ensure you, to not repeat this one again.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!