当前位置: 代码迷 >> Web前端 >> 处置传的地址有空格以及调试的使用debug
  详细解决方案

处置传的地址有空格以及调试的使用debug

热度:275   发布时间:2012-09-17 12:06:51.0
处理传的地址有空格以及调试的使用debug

通常我们在传递一个地址时如果有空格

String myString = "http://myhost.com/media/mp3s/9/Agenda of swine - 13. Persecution Ascension_ leave nothing standing.mp3" ; ?
URI myUri
= new URI ( myString ); ?
结果会抛出异常

java . net . URISyntaxException : Illegal character in path at index X?

?

其实很简单 只要把空格转换成别的字符就可以了

这里加设有空格的只在最后一个\ 后面

URI uri = new URI ( string . replace ( ' ' , '+' )); ?
或者

URI uri = new URI ( string . replace ( " " , "%20" )); ?
然后

int pos = string . lastIndexOf ( '/' ) + 1 ; ?
URI uri
= new URI ( string . substring ( 0 , pos ) + URLEncoder . encode ( string . substring ( pos ), "UTF-8" )); ?

2.

<application android:icon = "@drawable/icon" ?
? ?
android:name = ".SomeApp" ?
? ?
android:label = "@string/app_name" android:debuggable = "true" > ?
if ( Log . isLoggable ( TAG , Log . DEBUG )) { ?
? ?
Log . d ( TAG , "some log statement" ); ?
}

?

3. 在一个服务中调试 有时候断电不能固定

android.os .Debug .waitForDebugger ( ) ;
Java代码 ?收藏代码
  1. public ? class ?SoftKeyboard? extends ?InputMethodService???
  2. ????????implements ?KeyboardView.OnKeyboardActionListener?{??
  3. ??????????
  4. ????@Override ??
  5. ????????public ? void ?onConfigurationChanged(Configuration?newConfig)?{??
  6. ????????Log.d("SoftKeyboard" ,? "onConfigurationChanged()" );??
  7. ???
  8. ????????/*?now?let's?wait?until?the?debugger?attaches?*/ ??
  9. ????????android.os.Debug.waitForDebugger();??
  10. ??????????
  11. ????????super .onConfigurationChanged(newConfig);??
  12. ??????????
  13. ????????/*?do?something?useful...?*/ ??
  14. ??????????????????
  15. ????????}??
?
  相关解决方案