Results 1 to 10 of 10
  1. #1
    Feelux is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

    Default Null Pointer Exception in generating a JTable with TableCellRenderer

    So basically, i'm creating a JTable with an AbstractCellEditor and a TableCellRenderer.
    For each cell of the table, i create a JPanel with 3 labels.
    I'm getting a photo URL, name and a text from the database and i display it on the table.

    During initialization, i fill the table up with data. And i remove all the data and fill it up again when the user hits the 'Next' button.

    Here's the full source code, plus the 'Next' button's action performed:
    MEGAUPLOAD - The leading online storage and file delivery service

    It all goes well during initialization, but when i hit the 'Next' button, i get this error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at AnnotationManager.ButtonRenderer.getTableCellRende rerComponent(AnnotationList.java:240)
    at javax.swing.JTable.prepareRenderer(JTable.java:572 9)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(Basi cTableUI.java:2075)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(Bas icTableUI.java:1977)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTab leUI.java:1773)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.ja va:143)
    at javax.swing.JComponent.paintComponent(JComponent.j ava:763)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JViewport.paint(JViewport.java:747)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:5 67)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintToOffscreen(JComponent .java:5124)
    at javax.swing.RepaintManager$PaintManager.paintDoubl eBuffered(RepaintManager.java:1475)
    at javax.swing.RepaintManager$PaintManager.paint(Repa intManager.java:1406)
    at javax.swing.RepaintManager.paint(RepaintManager.ja va:1220)
    at javax.swing.JComponent._paintImmediately(JComponen t.java:5072)
    at javax.swing.JComponent.paintImmediately(JComponent .java:4882)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:803)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:714)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:694)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    Thank you in advanced!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Some might look at your link, but many will not. Have you inspected what's going on on the line that throws the NPE? You've got a null object that you're trying to dereference, and finding out which object this is usually will solve your problem for you. If not, then I suggest you create a small compilable and runnable program that reproduces the problem, and then post it here in the forum (using code tags) so we can run it and test it.

    Much luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Alright, I looked at your code, and even that code is not compilable for me, so there's no way I can help with the information provided. If you still have problems and desire our help, then my suggestion above is still, I feel, a good one.

  4. #4
    Feelux is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

    Default

    I have inspected the code over and over.
    I even printed the values on the line before the NPE, and it prints the actual values. And after printing, it generates a NPE on the line# of the System.out.println.

    I've attached the source file, i wrote comments too.
    It's quite hard to do an executable file of this project, coz it involves certain database queries. But, i'll try.
    Attached Files Attached Files

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Read my signature link on how to create SSCCE as it will give useful pointers. You'll need to get rid of the database code and simplify, simplify, simplify.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Cross-posted: Swing - Help! Null Pointer Exception in generating a JTable with TableCellRenderer

    Please do not cross-post without placing notifications and links in all of the cross-posts. The problem is that you're asking unpaid volunteers to help you here, not paid consultants, and most of us mind if we take time away from work/lives/play to try to help someone only to find that we've provided a solution that was already provided in a cross-post hours ago. The proper thing to do is that if you feel you must cross-post, at least provide links in each cross-post to the other, so that folks don't waste time answering something already answered and so that folks can review all discussions that have already occurred.

  7. #7
    Feelux is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

    Default

    My apologies, but i would've posted here if the problem was already solved. But still, i am sorry.

  8. #8
    Feelux is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks, Fubarable.
    I was creating a SSCCE, but it wasn't able to generate the AbstractCellEditor and the TableCellRenderer. So, i traced again the original code, and fortunately, i found the culprit.

    I've gone through the code again, and i noticed that the array that was passed wasn't completely filled with data, and when it was passed to the AbstractCellEditor and the TableCellRenderer, it read the data including those with no value, thus, NPE.

    I was looking at it all wrong, that's why i couldn't see the problem.

    Problem solved. Thanks :)

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Cool. I'm glad that you've solved this. If you haven't done so, you'll want to notify all cross-posts that you've found a solution and either tell the solution, or provide a link to this thread. Also, I've marked this thread "solved".

    Best of luck!

  10. #10
    Feelux is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 06:48 PM
  2. Null Pointer Exception
    By musasabi in forum New To Java
    Replies: 3
    Last Post: 05-12-2010, 03:52 AM
  3. Null pointer exception
    By talha06 in forum JDBC
    Replies: 5
    Last Post: 07-14-2009, 01:12 AM
  4. Help with null pointer exception
    By gammaman in forum New To Java
    Replies: 4
    Last Post: 07-14-2009, 12:23 AM
  5. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 03:30 AM

Tags for this Thread

Posting Permissions

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