Results 1 to 4 of 4
  1. #1
    vittoire is offline Member
    Join Date
    Jan 2010
    Posts
    9
    Rep Power
    0

    Default Debugging Help Needed

    /**
    * @(#)MainMemory2.java
    *
    *
    * @author
    * @version 1.00 2010/1/26
    */

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

    public class MainMemory2 extends JFrame{

    JLabel jlMSize, jlNoOfSegments, jlSpace, jl6, jlSegment;
    JButton jbBack, jbReset, jbGenerate, jbNext;
    JTextField jtfSize, jtfSegment;
    JSpinner jsSegment, jsSpace;
    JPanel jp1, jp2, jp3, jp4, jp5, jp6;

    public MainMemory2() {

    setSize(800,600);

    setTitle("Main Memory Management");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLayout(new BorderLayout());

    //initialize panels
    jp1= new JPanel();
    jp2= new JPanel();
    jp3= new JPanel();
    jp4= new JPanel();
    jp5= new JPanel();
    jp6= new JPanel();

    //set panel layout
    jp1.setLayout(new GridLayout(4,1)); //panels for left gui
    jp2.setLayout(new FlowLayout()); // Memory Size
    jp3.setLayout(new FlowLayout()); //No. of Segment
    jp4.setLayout(new FlowLayout()); // space/ segment
    jp5.setLayout(new FlowLayout()); //buttons
    jp6.setLayout(new GridLayout(2,1)); //panels for rite gui


    // Create spinner
    JSpinner jsSegment = new JSpinner();
    JSpinner jsSpace = new JSpinner();

    //Create Buttons
    jbBack = new JButton("Back");
    jbReset = new JButton("Reset");
    jbGenerate = new JButton("Generate");
    jbNext = new JButton("Next");

    //Create label
    jlMSize = new JLabel("Memory Size:");
    jlSegment = new JLabel("No. Of Segments:");
    jlSpace = new JLabel("Space/Segment:");
    jl6 = new JLabel("To");
    jlSegment = new JLabel("Segment Space");

    // Set spinner value
    jsSegment.setValue(new Integer(1));
    jsSpace.setValue(new Integer(200));

    //set textfield value
    jtfSize = new JTextField(5);
    jtfSegment = new JTextField("100", 4);

    jp1.add(jp2);
    jp1.add(jp3);
    jp1.add(jp4);
    jp1.add(jp5);

    jp2.add(jlMSize);
    jp2.add(jtfSize);
    jp3.add(jlNoOfSegments);
    jp3.add(jsSegment);
    jp4.add(jlSpace);
    jp4.add(jtfSegment);
    jp4.add(jl6);
    jp4.add(jsSpace);
    jp5.add(jbBack);
    jp5.add(jbReset);
    jp5.add(jbGenerate);
    jp6.add(jlSegment);
    jp6.add(jbNext);

    //add panels to frame
    add(jp1, BorderLayout.WEST);
    add(jp6, BorderLayout.EAST);

    setVisible(true);


    }

    public static void main(String[] args)
    {


    JFrame.setDefaultLookAndFeelDecorated(true);
    MainMemory2 frame = new MainMemory2();
    }
    }
    can someone help me see why i keep getting null exception pointer? i had the same problem in the past but im sure it is not the same as the previous error which i had.

    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:1045)
    at java.awt.Container.add(Container.java:365)
    at MainMemory2.<init>(MainMemory2.java:75)
    at MainMemory2.main(MainMemory2.java:104)

  2. #2
    Najeeb is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default

    How to debug this error

    String s="A";
    int a=Integer.parseInt(s);
    System.out.print(a);

    at runtime it give the following error.

    Exception in thread "main" java.lang.NumberFormatException: For input string: "A"
    at java.lang.NumberFormatException.forInputString(Unk nown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    C:\jexp>java MM2
    Exception in thread "main" java.lang.NullPointerException
            at java.awt.Container.addImpl(Unknown Source)
            at java.awt.Container.add(Unknown Source)
            at MM2.<init>(mm2.java:70)
            at MM2.main(mm2.java:92)
    Line 70 is
    Java Code:
            jp3.add(jlNoOfSegments);
    Looks like the JLabel jlNoOfSegments has not been instantiated and is thus null.

  4. #4
    vittoire is offline Member
    Join Date
    Jan 2010
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Debugging
    By daro in forum Eclipse
    Replies: 0
    Last Post: 07-22-2009, 06:02 PM
  2. Debugging with Eclipse 3.4.0
    By edcaru in forum New To Java
    Replies: 2
    Last Post: 11-07-2008, 07:27 AM
  3. Debugging In NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 12:13 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
  •