Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please can some one check my GUI code

0 views
Skip to first unread message

SIVAKACH

unread,
Jan 29, 2003, 1:13:31 PM1/29/03
to
I am just getting the hand of GridBagLayout and I just make a quick
knock up code but it produces a runtime error which is

java.lang.NullPointerException:

at java.awt.Container.addImpl(Container.java:313)

at java.awt.Container.add(Container.java:242)

at GUI.add(GUI.java:59)

at GUI.<init>(GUI.java:46)

at GUI.main(GUI.java:71)


Here is my code... thanks for any help


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class GUI extends JFrame implements ActionListener

{ public GUI()
{
setTitle("Language Algorithims");
setSize(1000,500);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)

{
System.exit(0);
}
});

Container contentPane = getContentPane();
GridBagLayout gbl = new GridBagLayout();
contentPane.setLayout(gbl);

grams = new JComboBox();
grams.setEditable(false);
grams.addItem("2");
grams.addItem("3");
grams.addItem("4");
grams.addItem("5");
grams.addItem("6");
grams.addItem("7");
grams.addItem("8");
grams.addItem("9");


ngramb= new JButton(" Compare Ngrams");
Zipf = new JButton("Zipf graph");

GridBagConstraints gbc = new GridBagConstraints();
gbc.fill =GridBagConstraints.BOTH;
gbc.weightx =0;
gbc.weighty = 100;
add(textArea1, gbc, 1,2,1,3);
gbc.anchor = GridBagConstraints.CENTER;


ngramb.addActionListener(this);
}

public void add(Component c, GridBagConstraints gbc, int x, int y, int
w, int h)
{
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
getContentPane().add(c, gbc);
}

public void actionPerformed(ActionEvent evt)
{

}


public static void main (String[]args)
{

Frame f = new GUI();
f.show();

}
private JTextArea textArea1;
private JTextArea textArea2;
private JTextArea textArea3;
private JScrollPane scrollPane;
private JScrollPane scrollPane1;
private JScrollPane scrollPane2;
private JScrollPane scrollPane3;
private JComboBox grams;
private JButton ngramb;
private JButton Zipf;


}

Bender

unread,
Jan 29, 2003, 3:32:42 PM1/29/03
to

"SIVAKACH" <SIVA...@aol.com> wrote in message
news:aa31348d.03012...@posting.google.com...

> I am just getting the hand of GridBagLayout and I just make a quick
> knock up code but it produces a runtime error which is
>
> java.lang.NullPointerException:

> add(textArea1, gbc, 1,2,1,3);

> private JTextArea textArea1;

Those three lines are the culprit, I think. You're not initializing textArea1
before you add it to the pane.

private JTextArea textArea1 = new JTextArea();


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003


0 new messages