我在Android代码中使用了StringUtils类。但生成异常,即找不到类。但是,我已经使用了该类的jar文件。请帮帮我!StringUtils类不能在Android中工作
7
A
回答
0
我的问题用下面的代码解决,我们不需要使用StringUtils jar来添加我们的项目。
我创建自己的类,即“RanjitString”替换为StringUtils。
public class RanjitString {
public static String substringBetween(String str, String open, String close) {
if (str == null || open == null || close == null) {
return null;
}
int start = str.indexOf(open);
if (start != -1) {
int end = str.indexOf(close, start + open.length());
if (end != -1) {
return str.substring(start + open.length(), end);
}
}
return null;
}
}
并直接访问静态方法substringBetween:
String myxml="This is my xml with different tags";
String successResult = RanjitString.substringBetween(myxml,
"<tag>", "</tag>");
此代码为我工作...
+0
请参阅@ user2160667的其他答案,使用TextUtils –
+1
@SerkanArıkuşu:但是没有substringBetween方法textUtils –
24
相关问题
- 1. 为什么在Android中不能识别StringUtils的Apache类?
- 2. 不能在Android工作室
- 3. Android类不工作
- 4. Twitter API不能在Android中工作
- 5. MailTo不能在Android WebView中工作
- 6. Modal组件不能在android中工作
- 7. Spinner.setOnLongClickListener()不能在Android中工作
- 8. javascript不能在android中工作
- 9. Android链接不能在webview中工作
- 10. AngularJS不能在Xamarin中工作Android Webview
- 11. ionic2 WebSocket不能在Android App中工作
- 12. OnTouchEvent在Android中不能正常工作
- 13. Facebook SSO不能在android中工作
- 14. overridePendingTransition在android中不能正常工作
- 15. 动画不能在android中工作
- 16. Onclick事件不能在Android中工作
- 17. mkdirs不能在android studio中工作avd
- 18. DateTime类不能在PHP/Apache中工作
- 19. My.User.CurrentPrincipal不能在类库中工作
- 20. Lodash mixin不能在JavaScript中工作类
- 21. @Async不能在REST类中工作
- 22. 选择类不能在chrome中工作
- 23. Android OnClick不能在Android 4.3上工作
- 24. Android Runnable不能在android 2.3上工作?
- 25. javascript中的StringUtils
- 26. Android SQLite不能在单独的类中工作
- 27. 不能到Android工作室
- 28. java.lang.NoClassDefFoundError:org.apache.commons.lang3.StringUtils
- 29. Android的MapView类工作不
- 30. Android DrawText不能在SurfaceView上工作
你有没有添加jar文件到构建路径? –
@Chirag Raval:是的,我已经使用了jar文件。 –
这在简单的java程序中工作正常。但是当我们在android中使用相同的代码时,会产生这种类型的错误。请任何人有想法,所以请帮助我。 –