on 10-24-2005 12:36 PM
Dear All,
How can i trap the exception.
<b>java.lang.NullPointerException</b>
Please send me the code..
Regds,
Anup
Hi Anup,
Before accessing any property or methods of an object you can check that object for a null.
Like
if ( myObject != NULL ){
here access its properties or methods..
}
else {
first create a new object and use it..
}
Hope this helps you.
Regards,
Narinder Hartala
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anup,
Broadly there are two types of Exceptions in JAVA, Checked and Unchecked exception. We can have a Try....Catch for a checked exception but we cant have that for an unchecked exception. NULLPOINTEREXCEPTION is an unchecked exception.
Check following links for more clarity.
http://www.javaworld.com/javaworld/jw-07-1998/jw-07-exceptions.html
http://www.javapractices.com/Topic129.cjp
http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html
http://www.devx.com/Java/Article/29253
If you got your answer plz close this thread.
Regards,
Narinder Hartala
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.