java - Why am I getting a nullpointer exception? (Beginner) -


this question has answer here:

i extremely frustrated this, , have been trying days try , fix it. have 2 classes, main , getnounlist

main:

import java.io.*; import java.util.*;  public class main {     public static void main(string[] args) throws filenotfoundexception {     getnounlist nouns = new getnounlist();  }// end main method }//end of main class 

getnounlist:

import java.io.*; import java.util.*;  public class getnounlist extends main { arraylist<string> listofwords;  public getnounlist() throws filenotfoundexception {     scanner list = new scanner(new file(     "/users/fareedmabrouk/desktop/explore/coding/java/businessideagenerator/coderepository/businessgen/src/nouns.txt"));  while (list.hasnextline()) {         listofwords.add(list.nextline());     } // end while loop     system.out.println(listofwords); }//end constructor }//end getnounlist class 

the file has random nouns this:

cat laptop dog headphones 

etc...

the error nullpointer exception @ line adding nouns file arraylist. can please me out?

listofwords never constructed.

replace

arraylist<string> listofwords; 

with

list<string> listofwords=new arraylist<>(); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -