contentpane - Java getContentPane() NullPointerException on JFormatterTextField -
i trying create jformatted text field, when try add it, nullpointerexception gets thrown @ me. checked if stuff in correct order or if isn't null, doesn't seem so. might wrong though.
here block of code
public static void showtopic(string path) throws ioexception{ path = "topics/"+path+".txt"; system.out.println(path); string[] topicfile = login.readfile(path); int b = login.readlines(path); topic.main(null); jformattedtextfield formattedtextfield = new jformattedtextfield(); formattedtextfield.seteditable(false); formattedtextfield.setbounds(50, 50, 100, 100); (int i=0;i<b;i++) formattedtextfield.settext(topicfile[i]); topic.contentframe.getcontentpane().add(formattedtextfield); }
and window frame
import java.awt.eventqueue; public class topic { static jframe contentframe; /** * launch application. */ public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { topic window = new topic(); window.contentframe.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } /** * create application. */ public topic() { initialize(); } /** * initialize contents of frame. */ private void initialize() { contentframe = new jframe(); contentframe.setbounds(100, 100, 550, 539); contentframe.setdefaultcloseoperation(jframe.exit_on_close); contentframe.getcontentpane().setlayout(null); jbutton btnnewbutton = new jbutton("new button"); btnnewbutton.setbounds(435, 0, 89, 23); contentframe.getcontentpane().add(btnnewbutton); } }
thanks in advance :)
Comments
Post a Comment