Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NullPointerException caused by JFrame.setVisible()

843805Feb 19 2007 — edited Feb 19 2007
I'm trying to make a status bar class for use with an app. The code for this class is below. Upon testing the thing i come upon the following exception:
Exception in thread "main" java.lang.NullPointerException
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WPanelPeer.restack(Unknown Source)
	at sun.awt.windows.WWindowPeer.restack(Unknown Source)
	at java.awt.Container.addNotify(Unknown Source)
	at java.awt.Window.addNotify(Unknown Source)
	at java.awt.Frame.addNotify(Unknown Source)
	at java.awt.Window.show(Unknown Source)
	at java.awt.Component.show(Unknown Source)
	at java.awt.Component.setVisible(Unknown Source)
	at java.awt.Window.setVisible(Unknown Source)
	at org.bio.sigve.gui.JStatusBar.main(JStatusBar.java:56)
I'm at a loss as to why I'm getting this. Line 56 is the line where f.setVisible(true) is called. Here's the class:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;


import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.border.BevelBorder;

public class JStatusBar extends JPanel {
	private Component[] columns;
	
	public JStatusBar(){
		super(new FlowLayout());
		setBorder(new BevelBorder(BevelBorder.LOWERED));
		createJStatusBar(1);
	}
	public JStatusBar(int cols) {
		super(new FlowLayout());
		createJStatusBar(cols);
	}
	
	private void createJStatusBar(int cols) {
		columns = new JLabel[cols];
		
		for(int i = 0; i<columns.length;i++) {
			columns[i] = new JLabel("");
			JPanel p = new JPanel();
			p.setBorder(new BevelBorder(BevelBorder.LOWERED));
			//p.add(columns);
add(p);
}


}
public void setComponent(Component c, int index) {

}
public Component getComponent(int index) {
return null;
}
public void setText(String text, int index) {
((JLabel)columns[index]).setText(text);
}
public static void main(String[] args) {
JFrame f = new JFrame();
JPanel rot = new JPanel(new BorderLayout());
f.getContentPane().add(rot);
JStatusBar status = new JStatusBar();
rot.add(status);
status.setText("Hei!", 0);
f.setVisible(true);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2007
Added on Feb 19 2007
1 comment
1,118 views