This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Getting a java.lang.StringIndexOutOfBoundsException Error  RSS feed

 
Ranch Hand
Posts: 1923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following generates a java.lang.StringIndexOutOfBoundsException Error

The string being parsed is:

//sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf



I am wanting to point to a file to make an attachment in javax.mail I am not sure if I use a UNC or URL path.
 
Sheriff
Posts: 5687
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good situation to illustrate why creating an SSCCE (short, self-contained, complete, compilable example) is such a good idea.  What happens when you execute this?
You get a better error, and there is nothing else to get in the way of seeing what's wrong.  Here's what I got:
Can you see what's wrong now?
 
Steve Dyke
Ranch Hand
Posts: 1923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote: Can you see what's wrong now?



I see it is line 7 but I thought I was using an escape in the replaceAll method "//". Do I have to make provision for the double "//" is the root string?

By the way,  I like your quote by the Apostle Paul in I Corinthians
 
Steve Dyke
Ranch Hand
Posts: 1923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Can you see what's wrong now?



Ok, I changed the replaceAll("/", "\\") with replaceAll("/", "\\\\") and am not getting the exception.

But me attachment code is still failing:

UnionNotification: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
UnionNotification: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: javax.mail.MessagingException: IOException while sending message;
 nested exception is:
java.io.FileNotFoundException: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf (A file or directory in the path name does not exist.)

Again, if I paste this path into browser it displays the contents of the file as expected.

 
Sheriff
Posts: 12991
217
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need to replace / with \ ? What happens if you don't do the replaceAll?
 
Steve Dyke
Ranch Hand
Posts: 1923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Do you really need to replace / with \ ? What happens if you don't do the replaceAll?



I get this:

SystemOut     O UnionNotification: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: javax.mail.MessagingException: IOException while sending message;
 nested exception is:
java.io.FileNotFoundException: /sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf (A file or directory in the path name does not exist.)
 
Steve Dyke
Ranch Hand
Posts: 1923
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it figured out. It was the attachment code in the javax.mail class. I changed up how the class handled the URL path.

Thanks for all the help.
 
Sheriff
Posts: 21603
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only use replaceAll if you need to replace something based on a regular expression. If you want to replace a simple string with another, use replace instead.
 
I am Arthur, King of the Britons. And this is a tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!