Results 1 to 2 of 2
  1. #1
    MonkeyMan is offline Member
    Join Date
    Jan 2012
    Posts
    45
    Rep Power
    0

    Default array of javax.swing.jTable returns nullpointer exception when accessed

    Heya!

    I got myself an array of 8 jTables on my frame.

    Java Code:
    public javax.swing.JTable[]swingTables;
    and

    Java Code:
            swingTables[0] = bm1;
            swingTables[1] = nm1;
            swingTables[2] = fm1;
            swingTables[3] = mt1;
            swingTables[4] = bt1;
            swingTables[5] = st1;
            swingTables[6] = pt1;
            swingTables[7] = tt1;
    when I try to to do this:

    Java Code:
            selectedRows[0] = bm1.getSelectedRows();
            selectedRows[1] = nm1.getSelectedRows();
            selectedRows[2] = fm1.getSelectedRows();
            selectedRows[3] = mt1.getSelectedRows();
            selectedRows[4] = bt1.getSelectedRows();
            selectedRows[5] = st1.getSelectedRows();
            selectedRows[6] = pt1.getSelectedRows();
            selectedRows[7] = tt1.getSelectedRows();
    I get a nullpointer exception from the first row.

    However, I can do this much earlier in the code and not receive a nullpointer exception:

    Java Code:
            bodyModel =(DefaultTableModel)bm1.getModel();
            neckModel =(DefaultTableModel)nm1.getModel();
            fretboardModel =(DefaultTableModel)fm1.getModel();
            markersType =(DefaultTableModel)mt1.getModel();
            bridgeType =(DefaultTableModel)bt1.getModel();
            saddleType =(DefaultTableModel)st1.getModel();
            pickupsType =(DefaultTableModel)pt1.getModel();
            tunersType =(DefaultTableModel)tt1.getModel();
    I don't seem to understand how I can fetch a model of bm1 jTable and store it no problem, but I cannot store the swing component bm1 itself without getting a NPE.

    Anyone informed care to explain? :)

  2. #2
    MonkeyMan is offline Member
    Join Date
    Jan 2012
    Posts
    45
    Rep Power
    0

    Default Re: array of javax.swing.jTable returns nullpointer exception when accessed

    Ah I think I solved it thank you :)

Similar Threads

  1. Reference an array so it can be accessed
    By DGates in forum New To Java
    Replies: 5
    Last Post: 02-06-2012, 10:12 PM
  2. Nimbus LaF doesn't recognize javax.swing.JTable?
    By rudeboy in forum AWT / Swing
    Replies: 10
    Last Post: 12-04-2011, 09:14 PM
  3. NullPointer Exception while clicking Jtable
    By Subhasri in forum AWT / Swing
    Replies: 1
    Last Post: 09-30-2011, 05:08 PM
  4. using javax.swing.JOptionPane in array
    By icedragon770 in forum AWT / Swing
    Replies: 12
    Last Post: 11-10-2008, 09:27 AM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 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
  •