• Post Reply Bookmark Topic Watch Topic
  • New Topic

Path problems  RSS feed

 
Ivan Kuljis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings!



I'm fighting with paths in windows workground. When I insert Apsolute path the code works, but with getResource or with a string manipulation it doesn't work.. I don't know where will user install the app.

I get next error: "Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 1"

Without replace methods I was getting:
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: C:\Users\Ultimativa\Documents\Magic%20Briefcase\JavaBeans\bin\reports\test.jrxml (The system cannot find the path specified)


Can I get some hint? Big thanks in advance
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not a path problem. It is attempting to get a the character at the position 1 in a String which is too short to have a position 1. Like the a in Campbell. But in a String < 2 characters long.
Does it actually arise in that code you showed us? What line number is given in the stack trace?
In replace(...), (line 08) how do you know that the space will only occur once?
If you use substring("File/:".length()) it will be obvious what you are doing and you won't need the comment. And wouldn't you need to test if the String begins with File:/
Does file:/ appear in paths on Windows®? Or is it File:\ which is the same length, so there need be no change to the substring() call?

And welcome to the Ranch
 
Ivan Kuljis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:That is not a path problem. It is attempting to get a the character at the position 1 in a String which is too short to have a position 1. Like the a in Campbell. But in a String < 2 characters long.
Does it actually arise in that code you showed us? What line number is given in the stack trace?
In replace(...), (line 08) how do you know that the space will only occur once?
If you use substring("File/:".length()) it will be obvious what you are doing and you won't need the comment. And wouldn't you need to test if the String begins with File:/
Does file:/ appear in paths on Windows®? Or is it File:\ which is the same length, so there need be no change to the substring() call?

And welcome to the Ranch


True, there might be more spaces. Thanks! It arrives in code I wrote.



My output is: Connection opened
String report without substring(): file:/C:/Users/Ultimativa/Documents/Magic%20Briefcase/JavaBeans/bin/reports/test.jrxml
Report that works: C:\Users\Ultimativa\Documents\Magic Briefcase\JavaBeans\bin\reports\test.jrxml
String report from url: C:/Users/Ultimativa/Documents/Magic%20Briefcase/JavaBeans/bin/reports/test.jrxml
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:658)
at java.util.regex.Matcher.appendReplacement(Matcher.java:762)
at java.util.regex.Matcher.replaceAll(Matcher.java:906)
at java.lang.String.replaceAll(String.java:2162)
at com.inv.mainFrame.input.InputPanelClass.actionPerformed(InputPanelClass.java:480)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you've run into the classic "too many(few) backslashes" problem.

report.replaceAll("/", "\\");

So you have "\\" to say to java.lang.String, "This is an actual backslash." But then you are passing "\" to java.util.regex, and it says, "where is the character I'm supposed to escape?" It doesn't know you need a actual backslash. So what you actually need is:

report.replaceAll("/", "\\\\");

Now java.lang.String says, "I'll send two backslashes. java.util.regex says, "I'll replace slash with an actual backslash."
 
Ivan Kuljis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I think you've run into the classic "too many(few) backslashes" problem.

report.replaceAll("/", "\\");

So you have "\\" to say to java.lang.String, "This is an actual backslash." But then you are passing "\" to java.util.regex, and it says, "where is the character I'm supposed to escape?" It doesn't know you need a actual backslash. So what you actually need is:

report.replaceAll("/", "\\\\");

Now java.lang.String says, "I'll send two backslashes. java.util.regex says, "I'll replace slash with an actual backslash."


Hah I like their talk! Hope that those basterds will start to talk with me in the future, so I'd save some time

Thanks! One question.. do you think that it's better to hold those .jrxml templates in MySQL db(as link for the file on server) and pull them out in need, or it's better to hold them on the pc, like I'm doing with pictures for gui?
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Kuljis wrote:
Hah I like their talk! Hope that those basterds will start to talk with me in the future, so I'd save some time


That would be nice, huh? Some day maybe there will be the English speaking programming language.


Thanks! One question.. do you think that it's better to hold those .jrxml templates in MySQL db(as link for the file on server) and pull them out in need, or it's better to hold them on the pc, like I'm doing with pictures for gui?


My guess would be in a DB, but you may want to start a new thread for a new question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!