cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.NullPointerException

Former Member
0 Kudos

Hi to all...

Can anybody give detail explanation abt java.lang.NullPointerException.

Note->Dont paste the links.

Urs GS

Accepted Solutions (1)

Accepted Solutions (1)

former_member187990
Participant
0 Kudos

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.

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.