0

I get:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 

..at the line of getting the value of row:

String ENTRY = (String) table.getModel().getValueAt(row, 2)`

This is the code:

tab.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
            @Override
public Component getTableCellRendererComponent(JTable table,
       Object value, boolean isSelected, boolean hasFocus, int row, int col) {

Super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);

String ENTRY = table.getModel().getValueAt(row,2).toString(); 

                if (!ENTRY.equals("active")) {
                    setBackground(Color.GREEN);
                }
                return this;
            }
        });`
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Hachachin
  • 89
  • 8
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) 3) *"any help please.."* Any question would be helpful. Don't presume we can intuit the question from the problem statement. – Andrew Thompson May 10 '17 at 09:24
  • Well, according to your code it seems like your "table" variable is not instanciated. So when you try to access its value you get a NPE... – rilent May 10 '17 at 09:26
  • @rilent, i saw some examples, and it worked for them, "tab" is my JTable, and "table" is parameter of `getTableCellRendererComponent` – Hachachin May 10 '17 at 09:32
  • *"i saw some examples, and it worked for them"* Obviously they were doing something different, possibly in code not shown in the uncompilable code snippet above. That is why I suggested posting an MCVE (well.. one of the reasons). Tip: Add @rilent (or whoever, the `@` is important) to *notify* the person of a new comment. – Andrew Thompson May 10 '17 at 09:40
  • @Hachachin We need more informations, what arguments are you passing to your getTableCellRendererComponent method – rilent May 10 '17 at 12:52

0 Answers0