Results 1 to 6 of 6

Thread: Error Msg

  1. #1
    ivy
    ivy is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default Error Msg

    Hi there,
    I got some problems running my program.

    what is the meaning of this error??

    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl(Unknown Source)
    at java.awt.Container.add(Unknown Source)
    at fyp.Firstpage.getJPanel(Firstpage.java:95)
    at fyp.coverpage.getJDesktopPane(coverpage.java:65)
    at fyp.coverpage.getJContentPane(coverpage.java:48)
    at fyp.coverpage.getJFrame(coverpage.java:31)
    at fyp.coverpage.main(coverpage.java:72)

    I cant run my program.

  2. #2
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

    Default

    This means, you are value of a particular variable is null and it is not supposed to be null.
    check the condition for null. For e.g if(something!=null){
    }

  3. #3
    ivy
    ivy is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    Hi there, i dunno which one to change. Can you kindly help me check???


    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Toolkit;

    import javax.swing.JDesktopPane;
    import java.awt.Rectangle;
    import java.awt.GridBagLayout;
    import javax.swing.JButton;
    import java.awt.SystemColor;
    import javax.swing.JLabel;
    public class coverpage {

    private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="351,91"
    private JPanel jContentPane = null;
    private JDesktopPane jDesktopPane = null;


    /**
    * This method initializes jFrame
    *
    * @return javax.swing.JFrame
    */
    private JFrame getJFrame() {
    if (jFrame == null) {
    jFrame = new JFrame();
    jFrame.setTitle("Coverpage");
    jFrame.setContentPane(getJContentPane());
    Dimension screenSize= Toolkit.getDefaultToolkit().getScreenSize();
    jFrame.setSize(screenSize.width,screenSize.height) ;
    jFrame.validate();
    }
    return jFrame;
    }

    /**
    * This method initializes jContentPane
    *
    * @return javax.swing.JPanel
    */
    private JPanel getJContentPane() {
    if (jContentPane == null) {
    jContentPane = new JPanel();
    jContentPane.setLayout(new BorderLayout());
    jContentPane.add(getJDesktopPane(),BorderLayout.CE NTER);
    }
    return jContentPane;
    }

    /**
    * This method initializes jDesktopPane
    *
    * @return javax.swing.JDesktopPane
    */

    public JDesktopPane getJDesktopPane(){
    if(jDesktopPane ==null){
    jDesktopPane = new JDesktopPane();
    jDesktopPane.setLayout(new BorderLayout());
    Firstpage homepage = new Firstpage(coverpage.this);
    jDesktopPane.removeAll();
    jDesktopPane.add(homepage.getJPanel(),BorderLayout .CENTER);
    }
    return jDesktopPane;
    }

    public static void main(String[] args){
    coverpage frame = new coverpage();
    frame.getJFrame().setVisible(true);
    }

    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Considering the error is occurring somewhere below here:
    at fyp.Firstpage.getJPanel(Firstpage.java:95)
    you haven't shown us the FirstPage code.

    You should also highlight the line involved.

    And use code tags.

  5. #5
    ivy
    ivy is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    This is my Firstpage code. But i cant find tat code that you are referring to.
    .................................................. .................................................. ...

    package fyp;

    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.Rectangle;
    import javax.swing.JLabel;
    import java.awt.Color;
    import javax.swing.JTextField;

    public class Firstpage {

    coverpage home = null;
    private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="39,16"
    private JLabel jLabel = null;
    private JLabel jLabel1 = null;
    private JLabel jLabel11 = null;
    private JLabel jLabel12 = null;
    private JLabel jLabel13 = null;
    private JLabel jLabel14 = null;
    private JLabel jLabel15 = null;
    private JTextField jTextField = null;
    private JTextField jTextField1 = null;
    private JTextField jTextField2 = null;
    private JTextField jTextField3 = null;
    private JLabel jLabel16 = null;
    private JTextField jTextField4 = null;
    public Firstpage(coverpage home){
    this.home = home;
    }

    /**
    * This method initializes jPanel
    *
    * @return javax.swing.JPanel
    */
    JPanel getJPanel() {
    if (jPanel == null) {
    jLabel16 = new JLabel();
    jLabel16.setBounds(new Rectangle(1008, 634, 266, 71));
    jLabel16.setText("");
    jLabel16.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/printiticon.jpg")));
    jLabel15 = new JLabel();
    jLabel15.setBounds(new Rectangle(1010, 508, 264, 73));
    jLabel15.setText("");
    jLabel15.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/helpicon.jpg")));
    jLabel14 = new JLabel();
    jLabel14.setBounds(new Rectangle(1003, 372, 272, 78));
    jLabel14.setText("");
    jLabel14.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/tutorialsicon.jpg")));
    jLabel13 = new JLabel();
    jLabel13.setBounds(new Rectangle(1011, 240, 265, 75));
    jLabel13.setText("");
    jLabel13.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/theoryicon.jpg")));
    jLabel12 = new JLabel();
    jLabel12.setBounds(new Rectangle(1008, -1, 267, 177));
    jLabel12.setText("");
    jLabel12.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/normalstresswords.jpg")));
    jLabel11 = new JLabel();
    jLabel11.setBounds(new Rectangle(1, 1, 100, 748));
    jLabel11.setText("");
    jLabel11.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/wordMOM.jpg")));
    jLabel = new JLabel();
    jLabel.setBounds(new Rectangle(100, 1, 910, 748));
    jLabel.setText("");
    jLabel.setIcon(new ImageIcon(getClass().getResource(
    "/coverpage_PIC/bay-bridge.jpg")));
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    jPanel = new JPanel();
    jPanel.setLayout(null);
    jPanel.setSize(new Dimension(1275, 750));
    jPanel.add(jLabel, null);
    jPanel.add(jLabel11, null);
    jPanel.add(jLabel12, null);
    jPanel.add(jLabel13, null);
    jPanel.add(jLabel14, null);
    jPanel.add(jLabel15, null);
    jPanel.add(getJTextField(), null);
    jPanel.add(getJTextField1(), null);
    jPanel.add(getJTextField2(), null);
    jPanel.add(getJTextField3(), null);
    jPanel.add(jLabel16, null);
    jPanel.add(getJTextField4(), null);
    jPanel.add(jLabel1, null);

    }
    return jPanel;
    }

    /**
    * This method initializes jTextField
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextField() {
    if (jTextField == null) {
    jTextField = new JTextField();
    jTextField.setBounds(new Rectangle(1005, 175, 270, 66));
    jTextField.setBackground(new Color(102, 0, 0));
    }
    return jTextField;
    }

    /**
    * This method initializes jTextField1
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextField1() {
    if (jTextField1 == null) {
    jTextField1 = new JTextField();
    jTextField1.setBounds(new Rectangle(1003, 312, 274, 62));
    jTextField1.setBackground(new Color(102, 0, 0));
    }
    return jTextField1;
    }

    /**
    * This method initializes jTextField2
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextField2() {
    if (jTextField2 == null) {
    jTextField2 = new JTextField();
    jTextField2.setBounds(new Rectangle(1003, 451, 272, 58));
    jTextField2.setBackground(new Color(102, 0, 0));
    }
    return jTextField2;
    }

    /**
    * This method initializes jTextField3
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextField3() {
    if (jTextField3 == null) {
    jTextField3 = new JTextField();
    jTextField3.setBounds(new Rectangle(1002, 580, 272, 56));
    jTextField3.setBackground(new Color(102, 0, 0));
    }
    return jTextField3;
    }

    /**
    * This method initializes jTextField4
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextField4() {
    if (jTextField4 == null) {
    jTextField4 = new JTextField();
    jTextField4.setBounds(new Rectangle(1002, 704, 272, 46));
    jTextField4.setBackground(new Color(102, 0, 0));
    }
    return jTextField4;
    }

    }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Which line is line 95?
    That's what the stack trace means...(Firstpage.java:95)...line 95 in FirstPage.java.

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •