Results 1 to 3 of 3
  1. #1
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default How to avoid "No Line found error"

    Please help me to find why this "No line found" error coming. trying to find the error for a long time.

    Java Code:
    import java.security.MessageDigestSpi;		
    
    import javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction;
    
    import java.util.*;
    import java.io.*;
    
    import javax.swing.*;
    public class test1 {
    	
    
    	public static void main(String[] args) throws IOException {
    		
    		
    
    		//Declare and initialize variables
    		String userName= null;
    		
    		String name[] = new String[3];
    		int score[] = new int[3];
    
    			
    			
    					
    		
    		
    		//INTRODUCTION
    		JOptionPane.showMessageDialog(null,"Welcome to the Java game!!");
    		
    		//For Input 
    		Scanner userInput= new Scanner(System.in);
    		//Prompt for user name
    		userName = JOptionPane.showInputDialog("Please enter your name: ");
    		
    		
    		//ADDED DO WHILE LOOP FOR VERSION 3
    		do
    		{
    		//Reset the score if player chooses to play again **ADDED IN VERSION 3**
    		 
    		//Display Main Menu & Prompt for menu choice			
    		 menuChoice = DisplayMainMenu();
    		 
    		
    				ReadInHighScores(name,score);
    				/*test*/
    				for(int i = 0; i < 3; i++)
    				{
    					System.out.println(name[i] + " " + score[i]);
    				}
    				System.out.println();
    				int userScore = 0;
    				String username = null;
    				
    				
    				CompareScores(userScore,username,name,score);
    				/*test*/
    				for(int i = 0; i < 3; i++)
    				{
    					System.out.println(name[i] + " " + score[i]);
    				}
    			String[] highName = null;
    			int[] highScore = null;
    			UpdateHighScores(highName,highScore);
                 
    				
    			break;
    			
    
    	
    		//Return type: int
    		
    				//Parameters: none
    				//Purpose: This method reads the highscore from text file "highscore.txt".
    				
    			 
    				public static void ReadInHighScores(String[] name, int[] score) throws IOException
    				{
    					
    					String blank;
    					
    					File inFile = new File("highscore.txt");
    					//declare a Scanner to read from the file
    					Scanner fileInput = new Scanner(inFile); 
    					for(int i=0;i<3;i++)
    					{
    						
    					name[i]=fileInput.next();
    					score[i] = fileInput.nextInt();
    					blank= fileInput.nextLine();
    					
    					
    					}
    					fileInput.close();
    					
    					
    					
    				}
    
    				public static void CompareScores(int userScore, String userName, String[] name, int[] score) throws IOException
    			
    				{
    					
    					
    					if(userScore>score[0])
    					{
    						// move [1] to [2]
    						score[2]=score[1];
    						name[2]=name[1];
    					System.out.println(name[2]);	
    						// move [0] to [1]
    						score[1] = score[0];
    						name[1]=name[0];
    						System.out.println(name[1]);	
    						//replace top score
    						
    						
    						
    						score[0] = userScore;
    						name[0] = userName;
    						System.out.println(name[0]);	
    					}
    					
    					else if(userScore>score[1])
    					{
    						
    						score[2]=score[1];
    						name[2]=name[1];
    						System.out.println(name[2]);	
    						
    						score[1] =userScore;
    						name[1] =userName;
    						System.out.print(name[1]);	
    						
    					}
    					
    					else if(userScore>score[2])
    					{
    						score[0]=userScore;
    						name[0] = userName;
    						System.out.print(name[0]);	
    						
    					}
    				
    				}
    				
    				public static void UpdateHighScores(String[] highName, int[] highScore) throws IOException
    				{
    
    					   PrintWriter outputFile = new PrintWriter("highscore.txt");
    					  // outputFile.print( highScore);
    					   //
    					   outputFile.print( highName);
    					   outputFile.close();
    					
    				}
    	
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to avoid "No Line found error"

    Not certain where in the code you are getting the error but one way is to do a try catch. But that is ugly and probably unnecessary. The other way is... did you read the Scanner API. Lot's of methods there.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to avoid "No Line found error"

    Why are you showing JOptionPanes and then expecting the user to input values from the command line?

    Can you also post the full exception you are getting, including stacktrace, and point out which line in your code it is occurring on, if the line numbers don't match with the code in the original post.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 19
    Last Post: 09-29-2012, 05:12 PM
  2. Replies: 0
    Last Post: 02-02-2012, 07:24 AM
  3. -jGRASP wedge2 error: command "javac" not found.
    By ncneeds in forum New To Java
    Replies: 0
    Last Post: 09-28-2011, 09:21 PM
  4. Replies: 12
    Last Post: 12-05-2008, 05:37 AM
  5. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •