
public class A {
int i;
int j;
void funA()
{
i = i+1;
System.out.println(i);
j = j+1;
System.out.println(j);
}
}
......................................................................
public class Demo<G> {
G x;
public static void main(String[] args) {
Demo<A> d3 = new Demo<A>();
try
{
d3.x.i = 5;//why Null pointer Exception
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Hi jagan,
Before you have assign the value for i, you should declare x object explicitly with new operator d3.x = new A(); d3.x.i = 5; Now null pointer exception won't come.
public class Demo<G> {
G x;
public static void main(String[] args) {
Demo<A> d3 = new Demo<A>();
try
{
d3.x = new A();
d3.x.i = 5;//why Null pointer Exception
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Please try with this code.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.