string index outofbounds exception

CD Tom

Member
Licensed User
Longtime User
I don't know why I'm getting this error because it was working before and I only added some columns to the csv file. Here's what I did.
In my access database I've created a query that extracts data to a .csv file the original query worked just fine I would email the file to my android device and save it in the download directory. My program would copy that file to the DirDefaultExternal with this code.
B4X:
      If File.Exists(File.DirRootExternal,"download/MBRS.csv") = True Then
         File.Copy(File.DirRootExternal,"download/MBRS.csv",File.DirDefaultExternal, "MBRS.csv")

      End If
The program would then run this code
B4X:
      table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",")
This was working fine until I add some columns to the query that extracts to the .csv file now when the above line is executed I get the error "table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",") java.lang.StringIndexOUtOfBoundsException: Length=48 index=1"
I tried to attach the .csv file but I get an invalid file when I try and upload it.
What do you need to help me find out what I did to get his error.
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Just had a look at your code. You are copying from dirRootExternal/downloads, to your dirDefaultExternal.
B4X:
    If FirstTime Then
        If File.Exists(File.DirRootExternal,"download/MBRS.csv") = True Then
            File.Copy(File.DirRootExternal,"download/MBRS.csv",File.DirDefaultExternal, "MBRS.csv")

            File.Delete(File.DirRootExternal, "download/MBRS.csv")
        End If
[/copy]

Are you sure that the file in the download folder is the same that you posted for us to check? I would suggest manually copying the very same one that you uploaded here, in the download folder, and then rerun your project.
Ah, now I see nr2 suggestion of Mahares. Yes, this seems to be the point. Make sure you have the very same file at your download folder.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, I finally found the problem. Let me explain and see if someone can tell me why this happened.
When I create the MBRS.csv file from the access database I attach it to an email and send that to my gmail account. I then get the email on my nexus and save the attachment which downloads it into the download folder. I've looked at the MBRS.csv file on the main computer but when I look at it on the nexus I see a message that there was an error I was thinking that it was an error trying to open the file but actually that was written in the csv file and everything else was gone.
When I copied the file from the main computer to the nexus everything worked. Now my question if I can't connect the nexus of what ever device the club will use what is the best way to get the data file from the computer to the other device.
Let me thank you all for you help and understanding
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I emailed the csv file (742KB) to myself sent to my gmail account. I opened the email on the Nexus 7. To the right of the attachment are the 3 dots which represent the menu. I clicked them and selected 'Save'. The file was saved to the Download folder of the Nexus 7. All of it was accounted for. I did not get any errors. In fact I was able to use it to rerun your programs. You might want to send it to your gmail account again, because surely, I did not encounter any problems or any empty or corrupted file.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, I'll give that a try again and see what happens. Thanks again for all your help.

That's real funny when I send it to my gmail account I don't get the file I send, it actually writes the error message in the csv file. Now when I send the file to my hotmail account it comes across correct. I would like to see if you get the same error, don't know if you want to give me gmail address but if you do I'll send you the file and see what you get.
 
Last edited:
Upvote 0
Top