on 06-22-2007 5:53 AM
Hi to all...
Can anybody give detail explanation abt java.lang.NullPointerException.
Note->Dont paste the links.
Urs GS
Hi,
A NullPointerException occurs when a null variable is sent a message, or in other words, when a receiver object is null.
This happens:
1)when variablesespecially instance variables or parametersare not initialized;
2)when a variable is assigned a null value, from another variable, from a method's return value, or directly from the keyword null;
3)when a null variable is passed as an argument to a method you did not write.
This does not directly cause a NullPointerException. The invoked method tries to send this null parameter a message, which causes the Exception.
Consider the Example
<b>public class test {
public static void main(String[] args)
{
try
{
File f=new File("c:
test");
String str[]=f.list();
for(int i=0;i<str.length;i++)
{
System.out.println(str<i>);
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}</b>
Here we are trying to get the Files and Directories in the Folder C:
test.
If directory <b>test</b> exists,It will display the Files and Folder in it.
If no such directory exists in the name <b>test</b> then a <b>null pointer exception</b> will be rasied.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sathish,
In WebDynPro perspective
Asumme
Node --Emp
---Id
---Name
wdContext.currentEmpElement().getName();Some times this will throw NullPointerException when Example Emp node Obejct is "null" or Size=0(zero)
General : If you perform any manipulations on null object you get NullPointerException.
Rgds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
A NullPointerException occurs, when you are trying to use a pointer without initializing it...(i.e) when you use a pointer which is NULL.(The name itself suggests it)
Regards,
Prabhakar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
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.