Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let's say I run the first JFrame window and then from the 1st frame I open the 2nd frame. 1st frame is still open and now I want to access the first frame from the 2nd frame but I get NullPointerException if I use any methods or Objects from the fist frame. Even I looked online but all the videos are only talking about how to access 2nd frame from 1st frame. Please help me on this.
Thanks.

What I have tried:

In the first frame:
//constructor
class2 c = new class2();
//constructor2
method1();

//method1();
//main class

In the second frame:
//constructor
class1 = new class1();//runs the constructor2
//Here I get an NullPointerException error
Posted
Updated 3-Jul-17 21:56pm
Comments
wseng 3-Jul-17 21:32pm    
class1 c = new class1();

1 solution

You should not create a new class1 in class2, you should use a reference to the original object. See Trail: Learning the Java Language (The Java™ Tutorials)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900