Method call to another class

I've come up with a null pointer error with this code.... :s

I have to classes Class1 and Class2

I wants Class1 to call a method from Class2.

In Class2 I have a print method. I wants Class1 to call this method.

I have

public Class Class1

{

private Class2 class2;

public Class1()

privatevoid printClass2Method()

{

class2.printMethod()

}

}

I hope thats clear enough...?

[NB: This is not my actual code, just a substitued example]

[796 byte] By [jordon24a] at [2007-11-27 0:51:01]
# 1
have you actually initialized class2?
georgemca at 2007-7-11 23:21:37 > top of Java-index,Java Essentials,New To Java...
# 2
> I've come up with a null pointer error with this code....The class2 variable is initialized to null. You never assign it a reference to a Class2 object.[url= http://www.tmorris.net/pubs/npe/]How to resolve a java.lang.NullPointerException[/url]~
yawmarka at 2007-7-11 23:21:37 > top of Java-index,Java Essentials,New To Java...
# 3
Thats a good point... cheers!
jordon24a at 2007-7-11 23:21:37 > top of Java-index,Java Essentials,New To Java...