using methods of other classes to "overwrite" variables
<p>i'm relativly new to java and experimantating a bit with javafx</p>

<p>i want to change a variable from class A while using a method from class B</p>

<p>Main: thats the main class, it contains all the needed stuff(shows the primaryStage etc) it does have an constructor, so its <strong>not</strong> creating an actual "main-object" </p>

<pre><code>public class Main extends Application {
Sub sub = new Sub();
int a;

// stuff

public void aMethod() {
sub.subMethod();
}

}
</code></pre>

<p>Sub: this class solely surpose is to change the variable a, it does not contain a constructor to create a "sub-object"</p>

<pre><code>public class Sub {
//stuff

subMethod(){
int a = 5;
}
</code></pre>

<p>if i put the line <code>Main main;</code> in the Sub class, the program will give me a nullpointer exception, if i'm calling the subMethod(). 
ok...i guess cause i didnt actually create the main object... so far so good.</p>

<p>BUT... if i put in the line <code>Main main = new Main();</code> the program wont even start giving me an "exception while running application" error</p>

<p>the strange thing though is, if i put the line <code>Main main = new Main();</code> in the subMethod...</p>

<pre><code>subMethod(){
Main main = new Main();
int a = 5;
}
</code></pre>

<p>...the damn thing actually works...(well its slow, guess because with every calling of the method its creating a new object)</p>

<p>why is that so? </p>

<p>and how is it done correctly? :)
(using methods of other classes to "overwrite" variables)</p>

<p>regards
Red</p>
