java - Inline class cause the application didn't run -



java - Inline class cause the application didn't run -

i have problem run application click run "java application" on eclipse; nil happened. tracked code , found next code cause app didn't run. if comment out, frame show. there no error when complier. tell me solve problem. in advance.

(comment source:c ){ string iconstring="abctestlocation"; printlist p=new printlist(iconstring, source.tostring()); newlist.add(p); if (source.thiscontent.length()>0){ p=new printlist("", source.thiscontent); }else{ p=new printlist("",""); } newlist.add(p); }

there whole java file

package pdfannotationpackage; import java.awt.borderlayout; import java.awt.dimension; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.util.arraylist; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.swingutilities; import javax.swing.table.defaulttablemodel; public class question extends jframe implements actionlistener { private static arraylist<printlist>newlist; private static defaulttablemodel tablemodel; public static void main(string[] args) { // todo auto-generated method stub swingutilities.invokelater(new runnable() { @override public void run() { new question(); } }); } public question(){ super("main form"); this.setminimumsize(new dimension(400, 500)); this.setdefaultcloseoperation(jframe.exit_on_close); this.setextendedstate(jframe.maximized_both); this.setlayout(new borderlayout()); // name jmenu & add together items jmenu menu = new jmenu("file"); jmenuitem m=new jmenuitem("print"); m.addactionlistener(this); menu.add(m); // add together jmenu bar jmenubar menubar = new jmenubar(); menubar.add(menu); //http://www.java2s.com/code/java/swing-jfc/dynamicmenuitemformdichildrenwindowandscrollbar.htm setjmenubar(menubar); arraylist<comment>c=new arraylist<comment>(); c.add(new comment("testing 123", "tester", 2)); c.add(new comment("", "tester", 2)); string txt="lorem ipsum dolor sit down amet, consectetur adipiscing elit. mauris tempor accumsan purus, vulputate auctor eros malesuada vitae. vivamus sed nisi lectus feugiat pulvinar. cras in elementum lacus, vitae pharetra massa. maecenas eros nulla, vulputate ac feugiat eu, ultricies quis lacus. etiam leo lorem, rutrum sit down amet eleifend id, consectetur in nibh. vestibulum in nisi european union odio interdum pharetra. vivamus sed feugiat enim. praesent ultricies sagittis accumsan. donec tempor, justo eget vehicula placerat, tortor mi sodales turpis, sed porta mauris sapien nunc."; txt=txt+ "\n\ndonec id orci mauris. morbi sed congue leo. integer id quam cursus, tempus nibh id, placerat magna. ut eleifend lorem condimentum pretium ultricies. sed nec dui quis purus scelerisque ultrices european union sit down amet tellus. vestibulum sapien odio, laoreet nec auctor tincidunt, porta nec magna. nulla ornare libero ullamcorper ultricies egestas. phasellus elementum sodales faucibus. nam in enim venenatis, tempor nulla in, mattis elit. nulla massa ligula, blandit fermentum ligula ut, rutrum malesuada nisi. phasellus vel facilisis libero."; txt=txt+"\n\nquisque sit down amet malesuada turpis. quisque tempus ultricies tortor, sed vehicula felis volutpat sed. aenean lectus diam, auctor sit down amet aliquam ut, mollis in ipsum. etiam id sollicitudin tellus, vitae auctor velit. vivamus porttitor purus vel lacinia faucibus. in sem odio, cursus quis mi vulputate, rutrum bibendum sapien. maecenas iaculis viverra lectus non consectetur. nulla eget dui non nisl sodales scelerisque ac vel tellus. mauris mattis sem molestie ipsum rutrum lobortis. quisque suscipit molestie massa nec consectetur. nulla hendrerit risus quis elit mattis venenatis. mauris sagittis @ quam non semper."; txt=txt+"\n\n\nmauris vitae porttitor ipsum. praesent feugiat, ligula sed aliquet sagittis, nibh justo posuere massa, sed vehicula erat metus vitae nulla. proin pulvinar, risus in posuere sagittis, libero massa mattis tellus, nec pharetra justo ipsum ac odio. nulla facilisi. aenean id enim tincidunt lacus tristique pellentesque. suspendisse fringilla tellus dolor. aliquam."; txt=txt+ "\n\ndonec id orci mauris. morbi sed congue leo. integer id quam cursus, tempus nibh id, placerat magna. ut eleifend lorem condimentum pretium ultricies. sed nec dui quis purus scelerisque ultrices european union sit down amet tellus. vestibulum sapien odio, laoreet nec auctor tincidunt, porta nec magna. nulla ornare libero ullamcorper ultricies egestas. phasellus elementum sodales faucibus. nam in enim venenatis, tempor nulla in, mattis elit. nulla massa ligula, blandit fermentum ligula ut, rutrum malesuada nisi. phasellus vel facilisis libero."; txt=txt+"\n\nquisque sit down amet malesuada turpis. quisque tempus ultricies tortor, sed vehicula felis volutpat sed. aenean lectus diam, auctor sit down amet aliquam ut, mollis in ipsum. etiam id sollicitudin tellus, vitae auctor velit. vivamus porttitor purus vel lacinia faucibus. in sem odio, cursus quis mi vulputate, rutrum bibendum sapien. maecenas iaculis viverra lectus non consectetur. nulla eget dui non nisl sodales scelerisque ac vel tellus. mauris mattis sem molestie ipsum rutrum lobortis. quisque suscipit molestie massa nec consectetur. nulla hendrerit risus quis elit mattis venenatis. mauris sagittis @ quam non semper."; txt=txt+"\n\n\nmauris vitae porttitor ipsum. praesent feugiat, ligula sed aliquet sagittis, nibh justo posuere massa, sed vehicula erat metus vitae nulla. proin pulvinar, risus in posuere sagittis, libero massa mattis tellus, nec pharetra justo ipsum ac odio. nulla facilisi. aenean id enim tincidunt lacus tristique pellentesque. suspendisse fringilla tellus dolor. aliquam."; c.add(new comment(txt, "tester3", 3)); (comment source:c ){ string iconstring="abctestlocation"; printlist p=new printlist(iconstring, source.tostring()); newlist.add(p); if (source.thiscontent.length()>0){ p=new printlist("", source.thiscontent); }else{ p=new printlist("",""); } newlist.add(p); } setvisible(true); } @override public void actionperformed(actionevent e) { // todo auto-generated method stub string command = e.getactioncommand().trim(); if (command.equalsignorecase("print")) { } } //inline class private static class comment{ private string thiscontent, thisauthor; private int thispage; private comment(string content, string author, int page){ thiscontent=content; thisauthor=author; thispage=page; } @override public string tostring() { homecoming thisauthor +"\t"+string.valueof(thispage); } } //inline class private static class printlist { private string text; private string icon; private printlist(string icon, string text){ this.icon=icon; this.text=text; } private string geticon(){ homecoming this.icon; } private string gettext(){ homecoming this.text; } } }

i compile code above , there error npe newlist field not instantiated, need instantiate arraylist first before actions on it.

problem:

private static arraylist<printlist>newlist; //was not instantaited

solution:

private static arraylist<printlist>newlist = new arraylist<printlist>();

java

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -