Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    jaiminparikh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default

    So, you say that the while loop will only read the first line...correct ?

  2. #22
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    So, you say that the while loop will only read the first line...correct ?
    No... what I said was the it will loop only once (because the the return statement is at the end of the while statement). It will execute any code in the while loop, but only once.

    So I ask again... where should the return statement be moved to?

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #23
    jaiminparikh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default

    I made the following change in the code, by taking the return statement outside the while loop.

    Java Code:
    public static double[] fileread(String fName) throws IOException  
    {
    
    String thisLine; //string variable to take each record at a time
    
    int count=0; 
    int x=0;
    
    
    
    double dblArray[];
    
    FileInputStream fis = new FileInputStream(fName); 
    //A FileInputStream obtains input from a file 
    
    DataInputStream myInput = new DataInputStream(fis);
    /*data input stream lets an application read primitive Java data types 
    from an underlying input stream*/
    
    while ((thisLine = myInput.readLine()) != null)
    { //beginning of outer while loop 
    
    String[] result = thisLine.split(",");
    dblArray = new double[result.length];
         for (x=0; x<result.length; x++)
         	
            {    	/*return result[x];*/ 
            	dblArray[x] = Double.parseDouble(result[x]);
            	
            		
             }
    
    } 
     	return dblArray;
    }
    But, it shows the following error:-

    C:\Users\Jaimin\Documents\JCreator Pro\MyProjects\finalcode2.java:69: variable dblArray might not have been initialized
    return dblArray;

    I have already declared dblArray variable in the beginning of the method. However, an error like above is shown. why ?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Combining Individual Sounds - Urgent
    By JDCAce in forum Advanced Java
    Replies: 4
    Last Post: 12-05-2008, 05:17 AM
  2. Replies: 1
    Last Post: 11-18-2008, 04:48 PM
  3. Help combining loops into 1 program.
    By kewlgeye in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 09:58 AM
  4. Hash table with separate chaining
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:42 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:26 AM

Posting Permissions

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