NullPointerException caused by JFrame.setVisible()

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;

publicclass JStatusBarextends 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);

}

privatevoid 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[i]);

add(p);

}

}

publicvoid setComponent(Component c,int index){

}

public Component getComponent(int index){

returnnull;

}

publicvoid setText(String text,int index){

((JLabel)columns[index]).setText(text);

}

publicstaticvoid 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);

}

}

>

[4806 byte] By [jhsvelia] at [2007-11-26 18:57:51]
# 1
Because you override JPane's getComponent(int index) method,and don't write it right way.
Eastsuna at 2007-7-9 20:37:46 > top of Java-index,Desktop,Core GUI APIs...