Results 1 to 6 of 6
  1. #1
    JDCAce's Avatar
    JDCAce is offline Member
    Join Date
    Oct 2008
    Location
    Columbus, GA, US
    Posts
    29
    Rep Power
    0

    Unhappy Problem Adding Content To JTabbedPane

    I'm trying to add stuff to this tabbed pane, but my compiler is showing a NullPointerException at the indicated line. What is wrong?

    Java Code:
    lengthFrom = new JList(listModel);
    lengthFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lengthFrom.setSelectedIndex(0);
    lengthFrom.addListSelectionListener(this);
    lengthFrom.setVisibleRowCount(5);
    JScrollPane lengthFromScroll = new JScrollPane(lengthFrom);
    tabLength.add(lengthFromScroll);  // NullPointerException
    
    lengthTo = new JList(listModel);
    lengthTo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lengthTo.setSelectedIndex(0);
    lengthTo.addListSelectionListener(this);
    lengthTo.setVisibleRowCount(5);
    JScrollPane lengthToScroll = new JScrollPane(lengthTo);
    tabLength.add(lengthToScroll);  // If I take out the problem line, this get a 
                                    // NullPointerException
    If you need more of my code than this, please let me know. This is getting very frustrating. I've been trying to solve this for at least an hour. I need some help!
    "Things are made of littler things that jiggle."

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    When posting questions about error messages, please post the full text of the error message.

    Where is the variable tabLength assigned a value? Is that the variable that has a null value?
    my compiler is showing ...
    Compilers don't show NPE. That error comes during execution.

  3. #3
    JDCAce's Avatar
    JDCAce is offline Member
    Join Date
    Oct 2008
    Location
    Columbus, GA, US
    Posts
    29
    Rep Power
    0

    Default

    Yes, you're right. It's a runtime error. The complete error message is as follows:
    Java Code:
    Exception in thread "main" java.lang.NullPointerException
            at MainGUI.createAndShowGUI(MainGUI.java:60)
            at MainGUI.main(MainGUI.java:144)
    I found the error. I actually never assigned tabLength a value. I didn't think that would throw a NullPointerException, though. That'll teach me...
    "Things are made of littler things that jiggle."

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JDCAce View Post
    I found the error. I actually never assigned tabLength a value. I didn't think that would throw a NullPointerException, though. That'll teach me...
    Nice, once an error found firs thing to do is debug your code and find exactly what happen on your code. In that way you can easily fix the issue.

  5. #5
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Can you post all your createAndShowGUI method please?

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 7
    Last Post: 07-09-2008, 12:06 AM
  2. Problem in adding sound.
    By shanky_sanks in forum Java Applets
    Replies: 6
    Last Post: 03-29-2008, 08:37 PM
  3. Active Content enable problem
    By kasipandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-01-2008, 02:15 PM
  4. Adding information to a JTable in a JTabbedPane
    By bigpappatrader in forum AWT / Swing
    Replies: 0
    Last Post: 12-05-2007, 07:09 AM
  5. Adding Tabs to JTabbedPane
    By blackstone in forum AWT / Swing
    Replies: 2
    Last Post: 11-14-2007, 03:15 PM

Posting Permissions

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