Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
Like Tree3Likes

Thread: Problems with loading a comma-seperated value file.

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Problems with loading a comma-seperated value file.

    Are there any println statements in the code? Are any of them printing out null?
    It shouldn't in any way be reading that null value
    Have you read the API doc for the method you are using to read the data? What does it say about returning a null value?
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    dddJewelsbbb is offline Computer Slave
    Join Date
    Jun 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: Problems with loading a comma-seperated value file.

    Problem resolved: I had to add a blank 8th line to the save files (just CSVFile.write("\n");) and added a reader for the 8th line at the end of the while loop. Hope anyone who has this problem sees this, as it's quite a simple, but really elusive error since it randomly adds a "null" out of absolutely nowhere. Thanks for the help anyway guys! I appreciate it :)

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Problems with loading a comma-seperated value file.

    You never explained where the null value was coming from.
    AFAIK there is no way to read a null value from a file.

    Adding lines to your file hides or ignores the error in your code.
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Problems with loading a comma-seperated value file.

    That is a hack of a fix.
    Form the documentation for BufferedReader.readLine() (which you should have read):
    "
    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
    "

    This is what people have been telling you.
    You were at the end of the file and reading a null.
    You should have been reading in the lines in a loop and exiting when the result of readLine() == null.

    Assumign you were working on a fixed format for the file, and so expecting a certain number of lines, then your code was clearly wrong as it was attempting to read an extra line that didn't exist, and so I would be questioning why the code expected an extra line, rather than hacking in a blank line just so it didn't fall over.
    Norm and Fubarable like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    dddJewelsbbb is offline Computer Slave
    Join Date
    Jun 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: Problems with loading a comma-seperated value file.

    Quote Originally Posted by Tolls View Post
    That is a hack of a fix.
    Form the documentation for BufferedReader.readLine() (which you should have read):
    "
    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
    "

    This is what people have been telling you.
    You were at the end of the file and reading a null.
    You should have been reading in the lines in a loop and exiting when the result of readLine() == null.

    Assumign you were working on a fixed format for the file, and so expecting a certain number of lines, then your code was clearly wrong as it was attempting to read an extra line that didn't exist, and so I would be questioning why the code expected an extra line, rather than hacking in a blank line just so it didn't fall over.
    This is specifically why I gave Furable rep, because after a while I figured out why I was having problems - both because he helped me and because he gave me the solution I didn't pay mind to until I was at wit's end. We all look over simple solutions sometimes right?

    Anyway, I was at line 2 out of 7 of the save file. It was giving me a null value before I even reached the third line. readLine() == null if statements would not have worked because it would have read
    0,0,100,0,0
    null
    as the String value rather than just "null" because it had other characters included. The solution entirely evaded me and my stupidity did not permit me to see the answer until - again - I was at wit's end. Again why I gave Furable more than deserved reputation.
    Last edited by dddJewelsbbb; 06-17-2012 at 09:35 AM.

  6. #26
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problems with loading a comma-seperated value file.

    More than deserved?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Reading a comma separated file into JTextPane
    By arndtmatt in forum New To Java
    Replies: 3
    Last Post: 04-09-2012, 11:08 PM
  2. MySQLDump to comma dilim text file
    By Sobutai in forum New To Java
    Replies: 1
    Last Post: 05-11-2011, 08:39 AM
  3. Java Regular Expressions: Comma Seperated List
    By sgtblitz in forum New To Java
    Replies: 3
    Last Post: 04-18-2011, 10:17 PM
  4. Delimite the file using comma
    By gokulcool in forum New To Java
    Replies: 3
    Last Post: 12-30-2008, 06:40 PM
  5. Replies: 7
    Last Post: 05-23-2008, 04:46 AM

Tags for this Thread

Posting Permissions

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