• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Out Of Bounds Exception, but where and how?  RSS feed

 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello


I have a little problem here I have been hacking away at it for the past hour and have exhausted my knowledge and am extending to here to ask for help. I am trying to create my download method for dropBox and am having a hard time evrytime I run this code when my user activates the ActionEvent for my Button ("Select") I will list the code below long with exception;













 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace will tell you the "where".

Please post it (UseCodeTags) and we can help you read it.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the value of FileDbxPath?
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm betting that FileDbxPath.lastIndexOf("/") returned a -1.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies guys. Still playing around with it and 'No-Go' Rob Spoor So the value is:


String TargetLocalPath = ".", FileDbxPath = "", FolderDbxPath="/";
String TargetDbxPath = "/", FileLocalPath = "", FolderLocalPath=".";



Carey Brown.. Yes, your statement is correct it is indeed returning that.



I should also mention that I am using the Dropbox API
 
Anurag Verma
Ranch Hand
Posts: 170
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see compilation errors, what are types of fileName and client?? where is client getting initialized?
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello , thanks for the reply.


DbxClient = client;

&


String fileName;



client is initialized in the other class.. would this be the problem?
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debug your code.
Never make assumptions about the values you are getting. We all think the code we write is correct and that the values we get in our methods are the ones we are expecting. We are quite often wrong.
So debug. Print out the values you are having issues with (usually as given by whatever exception you are getting) and work backwards from there, revisiting the assumptions you made when writing the code.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fileName = FileDbxPath.substring(FileDbxPath.lastIndexOf("/"));


This doesn't make sense to me. if FileDbxPath doesn't have any "/" in it (as you say is true), then this will cause an exception.
If FileDbxPath does have slashes (say, for example, "/home/users/abcdef/dbxPath" ) you will end up with filename = "/dbxPath" but there is (probably)no such file.
I think you want

which will work regardless of whether there are any slashes in the name.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies everyone.

I have applied the context and it seems to be moving through . Only problem Im getting now is this exception:

an 15, 2016 2:49:01 PM daword.dropboxFolder actionPerformed
SEVERE: null
java.io.FileNotFoundException: . (Is a directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
at daword.dropboxFolder.DbxDownloadFile(dropboxFolder.java:446)
at daword.dropboxFolder.actionPerformed(dropboxFolder.java:267)







Now I have checked over and tried track down and change the context but still to no prevail I keep getting the same exception..I don't really understand what I'm missing here as the files clearly exist because I am using a JTree and when the user selects the file that is displayed in this JTree the metadata is extracted and appended to a JText area where is is shown ( " fileILike.txt etc...) than the download method is executed in which when executed the exception is thrown ^ Is there something I am missing or confusing in here?



I am using this code a as framework https://github.com/Atin007/dbclient/blob/master/MyCloudJ_/src/CloudConnect/MyCloudJ_.java For this particular task as it helps me understand what is going on and am learning a new skill in the process, thanks guys.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error traceback tells it all. In DbxDoenloadFile you are tryoing to open an output stream for file SaveAsFile (NOTE: don't name variables starting with a capital letter).
But that file instance is created from fileName, which is the string ".", which is a directory, not a file.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyones help; I finally got it working for the most part now to add the fancy stuff... What I did was used the modified code Fred gave to me and removed the "." to "" in targetLocalPath and it essentially worked.. Had to look for a few moments for the photo I uploaded then downloaded back to test everything is going through well and was in my APP folder project for tonight is to make the user aware where the file is and to let them save it to a specified file. SO thanks everyone for your input, I appreciate it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!