Sunday, 15 September 2013

Exception in thread "main" java.lang.NullPointerException at tab.setTable(tab.java:36) -



Exception in thread "main" java.lang.NullPointerException at tab.setTable(tab.java:36) -

this question has reply here:

what null pointer exception, , how prepare it? 12 answers exception in thread "main" java.lang.nullpointerexception @ tab.settable(tab.java:36)

my code:

import java.awt.; import javax.swing.; import javax.swing.table.; import java.awt.event.; import javax.swing.; import javax.swing.event.; import java.net.*; public class tab extends jframe { int a; jtable jt; container c; static int k = 0; static int l = 0; static defaulttablemodel df; tab() { df = new defaulttablemodel(50, 0); jt = new jtable(df); df.addcolumn("request"); df.addcolumn("acknowledgement"); jt.setautoresizemode(jtable.auto_resize_all_columns); c = getcontentpane(); jscrollpane jsp = new jscrollpane(jt); c.add(jsp); setvisible(true); setsize(800, 800); } static void settable(string s) { df.setvalueat(s, k, 0); k++; } static void settable1(string s) { df.setvalueat(s, l, 1); l++; } }

if df should static (as now), shouldn't initialize in constructor (which initializes instance of class).

initialize in static block instead :

static { df = new defaulttablemodel(50, 0); }

java

No comments:

Post a Comment