当我尝试执行此代码时,我在java中遇到URL对象问题:
URL url = new URL("FTP://myname:mypassword@myServerIp/imagename.PNG;type=i");
我收到异常错误(MalformedURLException) 我认为这个问题是因为我的字符串有&,@但我不确定这个。
当我尝试另一个String URL时,它工作正常。 例如:
URL url = new URL("http://www.google.com");
我也尝试使用此代码编码我的字符串
String query = URLEncoder.encode(myString, "utf-8");
URL url = new URL(query);
并获得相同的异常错误。
你可以帮我吗?日志文件:
12-28 14:03:41.259:W /异常错误(7383):未找到协议:ftp%3A%2F%2Frsd48Image%3Asbol%3Fk63test%40192.111.7.17%2F20131228_140341.PNG%3Btype%3Di 12-28 14:03:41.259:W / System.err(7383):java.net.MalformedURLException:未找到协议:ftp%3A%2F%2Frsd48Image%3Asbol%3Fk63test%40192.111.7.17%2F20131228_140341.PNG%3Btype% 3DI 12-28 14:03:41.259:W / System.err(7383):at java.net.URL。(URL.java:178) 12-28 14:03:41.259:W / System.err(7383):at java.net.URL。(URL.java:127) 12-28 14:03:41.259:W / System.err(7383):at com.rsd48.mygooglemap.FileUpload.upload(FileUpload.java:69) 12-28 14:03:41.259:W / System.err(7383):at com.rsd48.mygooglemap.add_comment.onActivityResult(add_comment.java:103) 12-28 14:03:41.259:W / System.err(7383):在android.app.Activity.dispatchActivityResult(Activity.java:5231) 12-28 14:03:41.259:W / System.err(7383):在android.app.ActivityThread.deliverResults(ActivityThread.java:3172) 12-28 14:03:41.259:W / System.err(7383):在android.app.ActivityThread.handleSendResult(ActivityThread.java:3219) 12-28 14:03:41.259:W / System.err(7383):在android.app.ActivityThread.access $ 1200(ActivityThread.java:134) 12-28 14:03:41.259:W / System.err(7383):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1265) 12-28 14:03:41.259:W / System.err(7383):在android.os.Handler.dispatchMessage(Handler.java:99) 12-28 14:03:41.259:W / System.err(7383):在android.os.Looper.loop(Looper.java:137) 12-28 14:03:41.259:W / System.err(7383):在android.app.ActivityThread.main(ActivityThread.java:4856) 12-28 14:03:41.259:W / System.err(7383):at java.lang.reflect.Method.invokeNative(Native Method) 12-28 14:03:41.259:W / System.err(7383):at java.lang.reflect.Method.invoke(Method.java:511) 12-28 14:03:41.259:W / System.err(7383):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1007) 12-28 14:03:41.259:W / System.err(7383):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) 12-28 14:03:41.259:W / System.err(7383):at dalvik.system.NativeStart.main(Native Method) 12-28 14:03:50.558:W / System.err(7383):org.json.JSONException:formatted_address没有值 12-28 14:03:50.558:W / System.err(7383):at org.json.JSONObject.get(JSONObject.java:354) 12-28 14:03:50.558:W / System.err(7383):at org.json.JSONObject.getString(JSONObject.java:510) 12-28 14:03:50.558:W / System.err(7383):at com.rsd48.mygooglemap.LocationName.getJSON(LocationName.java:30) 12-28 14:03:50.558:W / System.err(7383):at com.rsd48.mygooglemap.Map $ 1.run(Map.java:246) 12-28 14:03:50.558:W / System.err(7383):在android.os.Handler.handleCallback(Handler.java:615) 12-28 14:03:50.558:W / System.err(7383):在android.os.Handler.dispatchMessage(Handler.java:92) 12-28 14:03:50.558:W / System.err(7383):在android.os.Looper.loop(Looper.java:137) 12-28 14:03:50.558:W / System.err(7383):在android.app.ActivityThread.main(ActivityThread.java:4856) 12-28 14:03:50.558:W / System.err(7383):at java.lang.reflect.Method.invokeNative(Native Method) 12-28 14:03:50.568:W / System.err(7383):at java.lang.reflect.Method.invoke(Method.java:511) 12-28 14:03:50.568:W / System.err(7383):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1007) 12-28 14:03:50.568:W / System.err(7383):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) 12-28 14:03:50.568:W / System.err(7383):at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
&
字符在网址中的该位置无效。