I am using StringUtils class in Android code. but exception generated i.e. class not found. But already i used jar file for that class. Please help me!
Asked
Active
Viewed 1.6k times
7
-
1Have you add jar file to build path ? – Chirag Sep 13 '12 at 11:02
-
@Chirag Raval : yes i already used jar file for that. – Ranjitsingh Chandel Sep 13 '12 at 11:09
-
This is working fine in simple java program. But when we use this same code in android that time generate this type of error. Please anybody have idea about that so please help me. – Ranjitsingh Chandel Sep 13 '12 at 11:11
-
This helped me: http://stackoverflow.com/questions/9857539/noclassdeffounderror-when-googleanalyticstracker-getinstance/9857669#9857669 – disco Oct 08 '12 at 08:41
2 Answers
25
Try not to use external libraries. Look always for an Android alternative.
For this specific case, you could use: android.text.TextUtils

Flow
- 23,572
- 15
- 99
- 156

Miguel Rivero
- 1,436
- 14
- 11
0
My problem solved with following code, We need not use StringUtils jar to add our project.
I create my own class i.e "RanjitString" replace with 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;
}
}
And directly access the static method substringBetween:
String myxml="This is my xml with different tags";
String successResult = RanjitString.substringBetween(myxml,
"<tag>", "</tag>");
This code is working for me...

k2col
- 2,167
- 18
- 18

Ranjitsingh Chandel
- 1,479
- 6
- 19
- 33
-
-
1@SerkanArıkuşu: But there is no substringBetween method in textUtils – Manoj Kumar Jun 06 '14 at 13:59