Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help! I am running out of ides

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help! I am running out of ides

    Hi i have this project for class in which i have to ask the user to input a file name add 5 lines to it close the file open it again and add anothr 5 lines, then post everything to the screen here is my code

     
    import java.io.*;
    import java.util.*;
     
    public class siasJorge_project_03
    {
         public static void main(String[] args)
         {
    		 PrintWriter outputStream=null;
    		 Scanner keyboard = new Scanner(System.in);
    		 String line = " ";
     
    		 int input = 0;
             int input2 = 0;
     
             String name = " ";
     
             System.out.println("Please enter the name of the file we will be working on, dont forget to add the extensiuon type...\n");
             name = keyboard.next();
     
             try
    		       {
    		         BufferedReader inputStream = new BufferedReader(new FileReader(name));
    		         System.out.println("Please enter 5 lines of text: ");
    				 	for (input=0; input<5; input++)
    				    	{
    				          line = keyboard.nextLine();
    				          outputStream.println(line);
    				        }
     
    		         inputStream.close();
     
    	  	         outputStream = new PrintWriter(new FileOutputStream(name, true));
    				 System.out.println("Please enter 5 more lines of text: ");
    				 	for (input2 = 0; input2 < 5; input2++)
    	 			    	{
    	 			          line = keyboard.nextLine();
    	 			          outputStream.println(line);
    	 			        }
     
    		         inputStream.close();
     
    				 line = inputStream.readLine();
    				 while (line != null)
    		          {
    	                System.out.println("The content of " + name + " is : " + line);
    		            line = inputStream.readLine();
              		  }
              		}
     
    		       catch (FileNotFoundException e)
    		       {
    		         System.out.println("File " + name + " was not found");
    		         System.out.println(" or could not be opened. ");
    		       }
    		       catch (IOException e)
    		       {
    		         System.out.println("Error reading from file " + name);
         		   }
    		}
    }

    The code compiles but crashes giving me a Exception in thread "main" java.lang.NullPointerException at sisJorge_project_03.main<siasJorge_project_03.java :27>

    any clue what i am doing wrong??

    ThankYou


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help! I am running out of ides

    java.lang.NullPointerException
    at sisJorge_project_03.main<siasJorge_project_03.java :27>
    Look at line 27 and find the variable that has a null value. Then backtrack in the code to find out why that variable does not have a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! I am running out of ides

    would that be for the line = keyboard.nextLine(); ??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help! I am running out of ides

    Can you look in your editor and count the lines?
    Or add a println that prints out the value of all the variables on the line and see if any of them are null.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. need to know how the code is running
    By Dark knight in forum Java Theory & Questions
    Replies: 3
    Last Post: July 19th, 2012, 09:28 AM
  2. running jinternalframe
    By cnjiru in forum AWT / Java Swing
    Replies: 0
    Last Post: May 25th, 2012, 12:49 PM
  3. KeyEvent Running Twice?
    By JuLiAnc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2012, 04:43 PM
  4. Running out of ideas...
    By Cat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2011, 11:21 AM
  5. Confusion about Java development IDES
    By neo_2010 in forum The Cafe
    Replies: 4
    Last Post: July 7th, 2009, 03:14 PM