1

I have a project that is due tonight that I have mostly completed but I am having a hard time putting a GUI on it, specifically getting the file printed onto the GUI rather than in the terminal window.

 private JFrame frame;
 private JTextArea area;
 private Font font;
 private Directory directory;
 private String name;
 private String firstName;
 private String lastName;

public GUI()
{
    makeFrame();
    directory = new Directory();
    directory.FileRead();
    String name = (firstName + lastName);
    directory.findPerson(name);
    directory.listDirectory();
    writeTextArea(name);
    font = new Font("Verdana", Font.PLAIN, 10);
 }

private void writeTextArea(String instr)
  {
    area.append(instr);
  }

I keep getting a NullPointerException for area.append(instr);. How do I fix this?

1
  • "..have a project that is due tonight .. but I am having a hard time putting a GUI on it.." You've left the GUI till the last day? I think you'll fail to finish in time. Commented Apr 20, 2014 at 1:15

1 Answer 1

2

private JTextArea area;

Your text area is null. You need to create an instance of it if you want to use it:

private JTextArea area = new JTextArea(5, 30);

and you also have to add it to the frame it you want to see the text.

I suggest you start with the Swing basics by reading the Swing tutorial. The section on Using Text Components has working examples.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.