java - NullPointerException when using a file as a input -
I was given a ready code sample for an assignment but I can not get it to work so Love!
  Package kth.id2010.lab.lab04; Import edu.princeton.cs.introcs.In; Import java.net.URL; Public class driver {public static zero main (string [] args) {url url = driver. Class.tatsource ("KAP1WTPT"); Input = new in (url); // This is where nullPointer is pointing while (! Input.isEmpty ()) {string line = input. Readline (). Trim (); String [] word = row split (""); For (string word: word) {System.out.println (word); }}}}    And here is the full exception which is printed.  
  Exception in the thread "main" java.lang.NullPointerException  
  at edu.princeton.cs.introcs.In (in.java:105)  
 at kth.id2010.lab.lab04.Driver.main (Driver.Java 12)    
 I am using maven  < / Div> 
 
  This is because your path is incorrect and the  URL  object is empty, please make sure that < Code> kap1.txt  file is under your resource path and not in any other folder, also try:    url = driver Lasktresr ( "/ kap1.txt");    See if you are not using resources   
 
  
Comments
Post a Comment