Hi all,

I have a main GUI class as seen here:

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

 * Class is to communicate with various other classes in the program to
 * create a roster for user based on their selection on GUI.
public class MainGUI extends JFrame
	private static final long serialVersionUID = 1L;
	//declares window width and height for program
	final int WINDOW_WIDTH = 1000;
	final int WINDOW_HEIGHT= 1000;
	private PlatoonPanel pp;
	private SquadPanel sp;
	private ManualPanel mp;
	private ActionButtons ab;
	private static Container pane;

	public MainGUI()
		//sets title
		setTitle("Roster Generator Version 0.0.1");
		//sets window width and height
		//sets default close operation
		pane = getContentPane();
		//creates new class objects
		pp = new PlatoonPanel();
		sp = new SquadPanel();
		mp = new ManualPanel();
		ab = new ActionButtons();
		//calls buildGUI() method
		//sets visible to true
	//method that combines all the other panels from other classes and
	//combines them into one
	public void buildGUI(){
		//sets border layout for main panel
		pane.setLayout(new BorderLayout());
		//adds other panels to this main panel
		pane.add(pp.getPlatoonRosterPanel(), BorderLayout.WEST);
		pane.add(sp.getSquadRosterPanel(), BorderLayout.CENTER);
		pane.add(mp.getManualRosterPanel(), BorderLayout.EAST);
		pane.add(ab.getButtonPanel(), BorderLayout.SOUTH);

And trying to have a driver class here for the main method:

 * Driver Class for program
public class MainDriver {

	public static void main(String[] args) {
		MainGUI mg = new MainGUI();



How can I communicate between these classes so that I do not receive this error:

Exception in thread "main" java.lang.NoSuchMethodError: main

Thanks for any help!

Recommended Answers

All 10 Replies

On which OS are u doing this?

Have u setup ur classpath properly?

OSX, I wrote it in eclipse compiler.

You need to setup ur classpath properly. Thats the problem.

Ok I'm not sure if I did it correctly, but I right clicked on the project in the project explorer and followed the build path option, now when I run the program I get:

Exception in thread "main" java.lang.NullPointerException
	at java.awt.Container.addImpl(Container.java:1045)
	at java.awt.Container.add(Container.java:365)
	at SquadPanel.<init>(SquadPanel.java:49)
	at MainGUI.<init>(MainGUI.java:35)
	at MainDriver.main(MainDriver.java:8)

looks like you're having a nullpointerexception in your MainGui class, on line 35. might want to check that out. something you're missing in the constructor of SquadPanel, perhaps?

could u post code of SquadPanel?

Here is SquadPanel Class:

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
 * Class is to create a panel to be added to MainGUI class. Panel is to contain four 
 * checkbox options for a squad roster. User can select any combination of checkboxes 
 * to have a roster printed out when a button is clicked on GUI to generate roster.
public class SquadPanel {

//creates data fields for checkboxes, borders, and panels.
private JCheckBox firstSquadRosterCB, secondSquadRosterCB, thirdSquadRosterCB, fourthSquadRosterCB, 
				  excludeRankCB, excludeSocCB, excludeBloodTypeCB, excludeRifleTypeCB,excludeRifleSerialCB, 
				  excludePeqSerialCB, excludeAcogSerialCB;
private TitledBorder squadSelectBorder, exclusionBorder, squadRosterBorder;
private JPanel squadRosterPanel, squadSelectPanel, exclusionPanel;
//private SquadPanel sp;

public SquadPanel(){
	//creates new panel objects
	squadRosterPanel = new JPanel();
	squadSelectPanel = new JPanel();
	exclusionPanel = new JPanel();
	//creates new checkbox objects 
	firstSquadRosterCB = new JCheckBox("First Squad");
	secondSquadRosterCB = new JCheckBox("Second Squad");
	thirdSquadRosterCB = new JCheckBox("Third Squad");
	fourthSquadRosterCB = new JCheckBox("Fourth Squad");
	//sets grid layout for squad selection panel
	squadSelectPanel.setLayout(new GridLayout(4,1));
	//adds squad check boxes to squad panel
	//creates new border object
	squadSelectBorder = new TitledBorder("Select Squads for Roster");
	//sets border to squad select panel
	//sets grid layout for excluded information panel
	exclusionPanel.setLayout(new GridLayout(7,1));
	//adds checks boxes to excluded panel 
	//creates new border object
	exclusionBorder = new TitledBorder("Select Information to be excluded");
	//sets border to exclusion panel
	//sets grid layout for squad roster panel
	squadRosterPanel.setLayout(new GridLayout(2,1));
	//adds squad select panel and exclusion panel to squad roster panel
	//creates new border object
	squadRosterBorder = new TitledBorder("Squad Roster");
	//sets border to squad roster panel
//getter that returns squad roster panel
public JPanel getSquadRosterPanel() {
	return squadRosterPanel;

on line 49 you're trying to add a excludeRankCB variable to the exclusionPanel, but you didn't instantiate one yet.
if you just put

JCheckBox excludeRankCB;

it will have default a null-value, so if you try to add this, you'll get a nullpointerexception.

OH JEEZE!!!!!! Of all the things I messed up on it was one that simple(to make it worse I forgot to create all of the excludeCB objects.....) Thanks for the help guys! Yeah I decided to add that group of JCheckBoxes to the program after I planned the GUI and I guess I just forgot a step. But the GUI runs now! Time for the hard part now. Thanks again!

Glad that uve got ur problem solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.