Simple line of java code is catching a UnsupportedEncodingException and I can't figure out why
I am completely stuck on this one. I know my code is correct. It is very simple. I have tried comparing what to null, using .equals, and now .length(), but it keeps catching this exception. Does anyone know what is going on?
public static void findLocations(String what, String near, String near2, String type) {
StringBuilder responseBuilder = new StringBuilder();
try {
URL url;
String tempURL = "http://.........";
if (what.length() != 0) { // This line is catching UnsupportedEncodingException
tempURL += "&category=" + URLEncoder.encode(what, "UTF-8");
}
if (near.length() != 0) {
Thread [<1> main] (Suspended)
LocationSet.findLocations(String, String, String, String) line: 85
SearchAlgorithm.editNear() line: 322
SearchAlgorithm.search(String, String) line: 90
SearchView.onClick(View) line: 281
Button(View).performClick() line: 2408
View$PerformClick.run() line: 8816
ViewRoot(Handler).handleCallback(Message) line: 587
ViewRoot(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line:开发者_C百科 not available [native method]
http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLEncoder.html#encode%28java.lang.String,%20java.lang.String%29
public static String encode(String s, String enc) throws UnsupportedEncodingException
The methode "URLENCODER.encode(what, "UTF-8") is the line, where you get the exception.
加载中,请稍侯......
精彩评论