I am getting the following error in RAD:
java.net.URISyntaxException: Illegal character in path at index 16: file:/E:/Program Files/IBM/SDP开发者_如何学Go/runtimes/base......
Could you please let me know what is the error and how to resolve it?
There's an illegal character at index 16. I'd say it doesn't like the space in the path. You can percent encode special characters like spaces. Replace it with a %20 in this case.
The question I linked to above suggests using URLEncoder:
String thePath = "file://E:/Program Files/IBM/SDP/runtimes/base";
thePath = URLEncoder.encode(thePath, "UTF-8");
I ran into the same thing with the Bing Map API. URLEncoder just made things worse, but a replaceAll(" ","%20");
did the trick.
Did you try this?
new File("<PATH OF YOUR FILE>").toURI().toString();
Had the same problem with spaces. Combination of URL and URI solved it:
URL url = new URL("file:/E:/Program Files/IBM/SDP/runtimes/base");
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
* Source: https://stackoverflow.com/a/749829/435605
I had a similar problem for xml. Just passing the error and solution (edited Jonathon version).
Code:
HttpGet xmlGet = new HttpGet( xmlContent );
Xml format:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<code>CA</code>
<name>Cath</name>
<salary>300</salary>
</employee>
Error:
java.lang.IllegalArgumentException: Illegal character in path at index 0: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contents>
<portalarea>CA</portalarea>
<portalsubarea>Cath</portalsubarea>
<direction>Navigator</direction>
</contents>
at java.net.URI.create(URI.java:859)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
at de.vogella.jersey.first.Hello.validate(Hello.java:56)
Not Exactly perfect Solution: ( error vanished for that instance )
String theXml = URLEncoder.encode( xmlContent, "UTF-8" );
HttpGet xmlGet = new HttpGet( theXml );
Any idea What i should be doing ? It just cleared passed but had problem while doing this
HttpResponse response = httpclient.execute( xmlGet );
the install directory can't have space. reinstall the software will correct it
If this error occurs with the jdk use this :
progra~1 instead of program files in the path example :
c:/progra~1/java instead of c:/program files/java
It will be ok always avoid space in java code.....
it can be used for every thing in program files, otherwise put quotes at the beginning and the en of path
"c:/..../"
I got this error today and unlike all the above answers my error was due to a new reason.
In my Japanese translation strings.xml file, I had removed a required string.
Some how android mixed up all the other string and this caused an error.
The solution was to include all the strings from my normal, English strings.xml
Including those strings which weren't translated to Japanese.
精彩评论