title: Passing.getText() String to another class
body: <p>I'm currently working on a first year university project and I have a problem, although I doubt it's a very complicated one, but I've been searching and I just can't find a suitable answer to it.</p>
  
  <p>The problem concerns two classes. A gui class (class1) and another class (class2), when I run the code the second class gives me a nullpointerexception when trying to retrieve the getText() String in class2 from class1.</p>
  
  <p>I have a JTextField in class1 and am trying to pass through the .getText() value to class2 and store it in a String type variable.</p>
  
  <p>The current code I'm trying to achieve this with is the following (simplified):</p>
  
  <pre><code> public class Class1 {
  
      private JTextField textField = new JTextField("Something");
  
        public Class1() {}
      ...
      public String getTextFieldString() {
        return textField.getText();
    }
  }
  
   public class Class2 {
  
     public Class2(Class1 class1) {
      c1=class1
     }
      private c1 Class1 = new Class1();
      private String s = new String();
      ...
      s = c1.getTextFieldString();
  }
  </code></pre>
  
  <p>I'm pretty new to coding, I've read that maybe I need to pass through an argument somewhere and I assume that's because textField is not static in itself, it changes when somebody enters a new value. (sorry for stating the obvious there.)</p>
  
  <p>Anyway, help is appreciated. Thanks a lot!</p>