size button from arraylist not working. HELP

Hi i have created an arraylist, and a jbutton, when i click this i want it to output the size of the arraylist. it compiles but gives noads of runtime errors. code is

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import java.io.*;

import java.util.*;

publicclass AddScheduleGUIextends JFrameimplements ActionListener, Serializable{

private JButton tmenu;

private JButton tButton;

private Font font;

private PrintWriter savefile;

private TeamList tTeamList;

public AddScheduleGUI(){

super("Create ");

Label title =new Label("CREATE ", JLabel.CENTER);

font =new Font("Ariel", Font.ITALIC, 30);

title.setBackground(Color.gray);

title.setForeground(Color.red);

title.setFont(font);

menu =new JButton("EXIT TO MENU");

menu.addActionListener(this);

tButton =new JButton("SIZE");

tButton.addActionListener(this);

JPanel titlePanel =new JPanel(new FlowLayout());

titlePanel.add(title);

Container contentPane = this.getContentPane();

contentPane.setLayout(new BorderLayout());

this.setBackground(Color.blue);

contentPane.setLayout(new GridLayout(5,3,5,5));

contentPane.add(titlePanel);

this.setLayout(new GridLayout(5,2));

this.add(menu);

this.add(tButton);

this.pack();

this.setVisible(true);

ClosingWindow close =new ClosingWindow();

addWindowListener(close);

TeamList tList =new TeamList();

tList.addTeam(new Team("Liverpool","Anfield"));

tList.addTeam(new Team("man u","ot"));

tList.addTeam(new Team("cheksea","sb"));

tList.addTeam(new Team("leics","fs"));

tList.addTeam(new Team("arse","emrites"));

tList.addTeam(new Team("blackburn","ewood"));

System.out.println(tList.size());

System.out.println("1st game: " + tList.get(0)+"VS" + tList.get(1));

System.out.println("2nd game: " + tList.get(1)+"VS" + tList.get(2));

System.out.println("3rd game: " + tList.get(2)+"VS" + tList.get(0));

};

publicvoid actionPerformed(ActionEvent evt)

{

if(evt.getSource() == menu)

{

new InformationGUI();

dispose();

}

elseif(evt.getSource() == tButton)

{

System.out.println("SIZE IS: " +tTeamList.size());

}

}

publicclass ClosingWindowextends WindowAdapter{

publicvoid windowClosing(WindowEvent e){

if(e.getSource() == menu){

ClosingWindow close =new ClosingWindow();

addWindowListener(close);

}

else{

System.exit(0);

}

}

}

}

Any ideas to why this is not working

[5538 byte] By [javaking312a] at [2007-11-26 15:04:26]
# 1

Just going to ask a few questions that I hope will point you in the right direction.

Firstly, what is the return type of the getSource() method? Do you think that youmay need to perform an explicit cast before testing for the source of the event? Also remember that you may need to protect the cast by testing the type of the object returned by the call.

Next is the == operator the correct way to test for equality in this case?

Tillermana at 2007-7-8 8:54:06 > top of Java-index,Java Essentials,Java Programming...
# 2

cheers mate but whta i wanted to know is why isnt this line of coding telling me the size

else if(evt.getSource() == tButton)

{

System.out.println("SIZE IS: " +tTeamList.size());

}

javaking312a at 2007-7-8 8:54:06 > top of Java-index,Java Essentials,Java Programming...
# 3
Because all it does is invoking size() of your TeamList instance, whatever that does.
CeciNEstPasUnProgrammeura at 2007-7-8 8:54:06 > top of Java-index,Java Essentials,Java Programming...
# 4

it dusnt mate, i keep getting errors like this

xception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at AddScheduleGUI.actionPerformed(AddScheduleGUI.java:87)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)

at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)

at java.awt.Component.processMouseEvent(Component.java:5488)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)

at java.awt.Component.processEvent(Component.java:5253)

at java.awt.Container.processEvent(Container.java:1966)

at java.awt.Component.dispatchEventImpl(Component.java:3955)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)

at java.awt.Container.dispatchEventImpl(Container.java:2010)

at java.awt.Window.dispatchEventImpl(Window.java:1778)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

javaking312a at 2007-7-8 8:54:06 > top of Java-index,Java Essentials,Java Programming...
# 5
So tTeamList is null. Maybe you want to fill it with an instance before using it?
CeciNEstPasUnProgrammeura at 2007-7-8 8:54:06 > top of Java-index,Java Essentials,Java Programming...