LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   NullPointerException (https://www.linuxquestions.org/questions/programming-9/nullpointerexception-209821/)

linux_ub 07-26-2004 10:43 AM

NullPointerException
 
Hi

i am writing a code which is using an array of objects ... when i try to run the code it gives me a nullpointer exception on line 24

Code:

import java.awt.Rectangle;
import java.awt.Color;
import javax.swing.*;

public class NewReport extends JInternalFrame{
       
        private JPanel reportPanel = new JPanel();
        private JLabel[] textLabels = new JLabel[10];
       
        public NewReport(Rectangle r) {
                super.setTitle("Report");
                super.setSize(r.width, r.height);
                super.setClosable(true);
                super.setIconifiable(true);
                super.setMaximizable(true);
                getContentPane().add(reportPanel);
                super.setBackground(Color.WHITE);
                reportPanel.setLayout(null);
                paintDesktop();
        }
       
        private void paintDesktop() {
                //JLabel toLabel = new JLabel();
                textLabels[0].setText("To");          // line 24
                textLabels[0].setBounds(4,12,16,11);
                reportPanel.add(textLabels[0]);
        }
}

where am i going wrong

thanks

pycoucou 07-26-2004 11:28 AM

You need to initialise all the JLabels of your array.

ie textLabels[0] = new JLabel();

it's the way I see that.

Cheers.

linux_ub 07-26-2004 11:38 AM

thanks a million ... it worked


All times are GMT -5. The time now is 10:03 PM.