View Single Post
Join Date: Oct 2004
Posts: 26
Reputation: SyLk is an unknown quantity at this point 
Solved Threads: 0
SyLk SyLk is offline Offline
Light Poster

Re: please enlighten me on what i need to do to get this right

 
0
  #3
Sep 29th, 2008
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class program1 {
  5. static Scanner filescan = null;
  6.  
  7. public program1(){
  8. try {
  9. filescan = new Scanner (new File("t.txt"));
  10. } catch (FileNotFoundException fe){
  11. fe.printStackTrace();
  12. }
  13. }
  14. public static void main(String[] args)throws IOException{
  15.  
  16. printFile();
  17.  
  18. }
  19.  
  20. public static void printFile()throws IOException{
  21.  
  22.  
  23. while(filescan.hasNextInt())
  24. System.out.println(filescan.nextInt());
  25.  
  26. }
  27.  
  28. }

I have tried this and i get -------->
Exception in thread "main" java.lang.NullPointerException
at program1.printFile(program1.java:23)
at program1.main(program1.java:16)
Reply With Quote