Performance tuning for JavaRDD function - java

I want to convert dataframe to Array of Json using Java and Spark version 1.6, for which am converting the data from
Dataframe -> Json -> RDD -> Array
where the data looks like this.
[
{
"prtdy_pgm_x":"P818_C",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Cost",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:19.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
{
"prtdy_pgm_x":"P818_I",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Tooling",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:20.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
{
"prtdy_pgm_x":"P818_W",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Weight",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:20.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
......
]
so I wrote my code something like this.
if(cmnTableNames != null && cmnTableNames.length > 0)
{
for(int i=0; i < cmnTableNames.length; i++)
{
String cmnTableName = cmnTableNames[i];
DataFrame cmnTableContent = null;
if(cmnTableName.contains("PTR_security_t"))
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName + " where fbrn04_snapshot_d = '" + snapshotId + "'");
}
else
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName);
}
String cmnTable = cmnTableName.substring(cmnTableName.lastIndexOf(".") + 1);
if (cmnTableContent.count() > 0)
{
String cmnStgTblDir = hdfsPath + "/staging/" + rptName + "/common/" + cmnTable;
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2); //This Part, takes more time than usual contains large set of data.
String output = "["+result+"]";
ArrayList<String> outputList = new ArrayList<String>();
outputList.add(output);
JavaRDD<String> finalOutputRDD = sc.parallelize(outputList);
String cmnStgMrgdDir = cmnStgTblDir + "/mergedfile";
if(dfs.exists(new Path(cmnStgTblDir + "/mergedfile"))) dfs.delete(new Path(cmnStgTblDir + "/mergedfile"), true);
finalOutputRDD.coalesce(1).saveAsTextFile(cmnStgMrgdDir, GzipCodec.class);
fileStatus = dfs.getFileStatus(new Path(cmnStgMrgdDir + "/part-00000.gz"));
dfs.setPermission(fileStatus.getPath(),FsPermission.createImmutable((short) 0770));
dfs.rename(new Path(cmnStgMrgdDir + "/part-00000.gz"), new Path(CommonPath + "/" + cmnTable + ".json.gz"));
}
else
{
System.out.println("There are no records in " + cmnTableName);
}
}
}
else
{
System.out.println("The common table lists are null.");
}
sc.stop();
but while reduce function is applied it's taking more time
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2); //This Part, takes more time than usual contains large set of data.
the table with the partition "PTR_security_t" is huge and takes a lot of time compared to other tables which don't have partitions (40-50 mins odd for 588kb)
I Tried Applying Lambda but i ended up with Task not serializable error. Check the code below.
if(cmnTableNames != null && cmnTableNames.length > 0)
{
List<String> commonTableList = Arrays.asList(cmnTableNames);
DataFrame commonTableDF = sqc.createDataset(commonTableList,Encoders.STRING()).toDF();
commonTableDF.toJavaRDD().foreach(cmnTableNameRDD -> {
DataFrame cmnTableContent = null;
String cmnTableName = cmnTableNameRDD.mkString();
if(cmnTableName.contains("PTR_security_t"))
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName + " where fbrn04_snapshot_d = '" + snapshotId + "'");
}
else
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName);
}
String cmnTable = cmnTableName.substring(cmnTableName.lastIndexOf(".") + 1);
if (cmnTableContent.count() > 0)
{
String cmnStgTblDir = hdfsPath + "/staging/" + rptName + "/common/" + cmnTable;
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2);
String output = "["+result+"]";
ArrayList<String> outputList = new ArrayList<String>();
outputList.add(output);
JavaRDD<String> finalOutputRDD = sc.parallelize(outputList);
String cmnStgMrgdDir = cmnStgTblDir + "/mergedfile";
if(dfs.exists(new Path(cmnStgTblDir + "/mergedfile"))) dfs.delete(new Path(cmnStgTblDir + "/mergedfile"), true);
finalOutputRDD.coalesce(1).saveAsTextFile(cmnStgMrgdDir, GzipCodec.class);
fileStatus = dfs.getFileStatus(new Path(cmnStgMrgdDir + "/part-00000.gz"));
dfs.setPermission(fileStatus.getPath(),FsPermission.createImmutable((short) 0770));
dfs.rename(new Path(cmnStgMrgdDir + "/part-00000.gz"), new Path(CommonPath + "/" + cmnTable + ".json.gz"));
}
else
{
System.out.println("There are no records in " + cmnTableName);
}
});
}
else
{
System.out.println("The common table lists are null.");
}
sc.stop();
is there any efficient way where i can enhance my Performance ?

Related

How to optimized multiple for loops to make code more readable

I've written a method to read json and generate data based on different combination.
For example lets say I've 3 json parameter and i wanna pass different permutation of json data.
So combination would be :
1 - F,T,T
2 - T,F,T
3 - T,T,F
4 - T,T,T
I used negativeCaseList to get false data and postitiveCaseList to get true data.
My task is to optimize this code to make it more readable.
Any suggestion is highly appreciated.
for (int i = 0; i < negativeCaseList.size(); i++) {
if (!negativeCaseList.get(i).isEmpty()) {
ArrayList<?> negativeDataAsList = (ArrayList<?>) negativeCaseList.get(i);
for (int j = 0; j < negativeDataAsList.size(); j++) {
ParameterData negativeParameterData = (ParameterData) negativeDataAsList.get(j);
for (int k = 0; k < postitiveCaseList.size(); k++) {
ArrayList<?> positiveDataAsList = (ArrayList<?>) postitiveCaseList.get(k);
for (int l = 0; l < positiveDataAsList.size(); l++) {
ParameterData positiveParameterData = (ParameterData) positiveDataAsList.get(l);
if (Utility.validateString(negativeParameterData.getParameterName())) {
if (!negativeParameterData.getParameterName().equals(positiveParameterData.getParameterName())) {
if (!positiveParameterData.parameterType.startsWith("System")) {
dictionary.put(positiveParameterData.getParameterName(), positiveParameterData.getValue());
} else {
dictionary.put(positiveParameterData.getParameterName(), positiveParameterData.getValue());
}
paramName = positiveParameterData.getParameterName() + "," + paramName;
if (Utility.hasHTMLTags(positiveParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + positiveParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = positiveParameterData.getValue() + "," + paramValue;
}
} else {
dictionary.put(negativeParameterData.getParameterName(), negativeParameterData.getValue());
paramName = negativeParameterData.getParameterName() + "," + paramName;
if (Utility.hasHTMLTags(negativeParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + negativeParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = negativeParameterData.getValue() + "," + paramValue;
}
}
} else {
listofParameter = negativeParameterData.getValue();
if (Utility.hasHTMLTags(negativeParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + negativeParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = negativeParameterData.getValue() + "," + paramValue;
}
}
}
}
//json ="";
if (!dictionary.isEmpty()) {
json = ParameterTransform.ObjectToString(dictionary);
} else {
json = ParameterTransform.ObjectToString(listofParameter);
}
preData.putAll(Utils.fillTestDetailsInPreData(requestRule));
if (requestRule.getiRegistrationNo()) {
JSONObject stringToJson = new JSONObject(json);
json = securityObject.buildMainJson("10401", "f41f9ac6-1090-4851-bc7a-4a2355dd10c4",
stringToJson);
}
jsons.add(json);
app_logs.info("Json " + jsons);
//reportData.add(json+"|"+paramName+"|"+paramValue);
if (Utility.hasHTMLTags(json)) {
reportData.add("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + json + "</xmp>");
} else {
reportData.add(json);
}
pName.add(paramName.toString());
pValue.add(paramValue.toString());
app_logs.info("data " + reportData);
//app_logs.info("pName : " + pName.toString());
//app_logs.info("pValue : " + pValue.toString());
paramName = "";
paramValue = "";
}
}
}

How to GROUP BY in where clause with ContentProvider?

Helo, I've got this code, which query the instances in calendarcontract:
Uri uri = Uri.parse(CalendarContract.Instances.CONTENT_URI + "/" +
Long.toString(from) + "/" +
Long.toString(to));
String[] mProjection =
{
CalendarContract.Instances._ID,
CalendarContract.Instances.EVENT_ID,
CalendarContract.Instances.CALENDAR_ID,
CalendarContract.Instances.TITLE,
CalendarContract.Instances.EVENT_LOCATION,
CalendarContract.Instances.DESCRIPTION,
CalendarContract.Instances.EVENT_COLOR,
CalendarContract.Instances.DTSTART,
CalendarContract.Instances.DTEND,
CalendarContract.Instances.EVENT_TIMEZONE,
CalendarContract.Instances.EVENT_END_TIMEZONE,
CalendarContract.Instances.DURATION,
CalendarContract.Instances.ALL_DAY,
CalendarContract.Instances.RRULE,
CalendarContract.Instances.RDATE,
CalendarContract.Instances.EXDATE
};
ContentResolver cr2 = this.c.getContentResolver();
String selection2 = "( " + selection_allcalendars + " (" + CalendarContract.Instances.RRULE + " IS NOT NULL) AND (deleted != 1) AND (" + CalendarContract.Instances.ALL_DAY + " = 0))";
Cursor cur2 = cr2.query(uri, mProjection, selection2, null, CalendarContract.Instances.DTSTART + " ASC");
How can I remove double instances from query? I want to use a "GROUP BY" clause, but I don't know how to do that.
Please help me :-)
Thanks!
Edit:
I want to group by EVENT_ID, because I get multiple entries. This ist the whole code I use for recurring events:
ContentResolver cr2 = this.c.getContentResolver();
String selection2 = "( " + selection_allcalendars + " (" + CalendarContract.Instances.RRULE + " IS NOT NULL) AND (deleted != 1) AND (" + CalendarContract.Instances.ALL_DAY + " = 0))";
Cursor cur2 = cr2.query(uri, mProjection, selection2, null, CalendarContract.Instances.DTSTART + " ASC");
ArrayList<String> checkexists = new ArrayList<>();
while (cur2.moveToNext()) {
String eventid = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_ID));
if(checkexists.contains(eventid)) {
}
else {
checkexists.add(eventid);
String rrule = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.RRULE));
TimeZone tz = TimeZone.getTimeZone("Europe/Berlin");
Long dtstart;
try {
dtstart = Long.parseLong(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DTSTART)));
dtstart = tz.getOffset(dtstart) + dtstart;
} catch (NumberFormatException e) {
dtstart = 0l;
}
Long dtend;
try {
dtend = dtstart + RFC2445ToMilliseconds(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION)));
/* dtend = Long.parseLong(cur.getString(cur.getColumnIndex(CalendarContract.Events.DTEND)));
dtend = tz.getOffset(dtend) + dtend; */
} catch (NumberFormatException e) {
dtend = 0l;
}
Calendar cal4 = Calendar.getInstance();
cal4.setTimeInMillis(dtstart);
LocalDate localdate = new LocalDate(cal4.get(Calendar.YEAR), cal4.get(Calendar.MONTH) + 1, cal4.get(Calendar.DAY_OF_MONTH));
long calendar_id = Long.valueOf(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.CALENDAR_ID)));
String id = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances._ID));
String title = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.TITLE));
String eventlocation = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_LOCATION));
String description = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DESCRIPTION));
String eventcolor = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_COLOR));
String eventtimezone = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_TIMEZONE));
String eventtimezone_end = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_END_TIMEZONE));
String duration = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION));
int allday = Integer.valueOf(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.ALL_DAY)));
rrule = "RRULE:" + rrule;
long lastrecurrencetime;
if(rrule.contains("UNTIL")) {
lastrecurrencetime = RruleHelper.getUntil(rrule).getTimeInMillis();
}
else {
lastrecurrencetime = -1;
}
//System.out.println("EEE: " + title + " " + rrule);
try {
ArrayList<ReadEvent> recurrenceevents = new ArrayList<>();
for (LocalDate date : LocalDateIteratorFactory.createLocalDateIterable(rrule, localdate, true)) {
// System.out.println("GGG:" + title + " " + i);
Calendar newcal_from = Calendar.getInstance();
newcal_from.setTimeInMillis(dtstart);
newcal_from.set(Calendar.DAY_OF_MONTH, date.getDayOfMonth());
newcal_from.set(Calendar.MONTH, date.getMonthOfYear() - 1);
newcal_from.set(Calendar.YEAR, date.getYear());
long dtstart_new = newcal_from.getTimeInMillis();
long dtend_new = dtstart_new + RFC2445ToMilliseconds(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION)));
if (dtstart_new >= from && dtstart_new <= to) {
ReadEvent newreadevent = new ReadEvent(calendar_id, id, eventid, title, eventlocation, description, eventcolor, dtstart_new, dtend_new, eventtimezone, eventtimezone_end, duration, allday, rrule);
newreadevent.setFirstReccurenceTime(dtstart);
newreadevent.setLastReccurenceTime(lastrecurrencetime);
if(!checkIfAlreadyExits(readevent, newreadevent)) {
//newreadevent.setReccurenceCount(i);
readevent.add(newreadevent);
}
}
if (dtstart_new > to) {
break;
}
}
} catch (Exception e) {
}
}
}

Why is my jpql .getResultList() returning 0 rows for a good query

I was using the exact same query yesterday and it was working fine today I made a few changes to flow of the program and the query no longer returns and rows.
the first function that my programs goes to:
public void prepareSummary(Date startDate , Date endDate)
{
int getStartDay = getDayFromDate(startDate);
int getStartMonth = getMonthFromDate(startDate);
//
int getEndDay = getDayFromDate(endDate);
int getEndMonth = getMonthFromDate(endDate);
int getYear = getYearFromDate(startDate);
if(getStartMonth <= getEndMonth)
{
if(getStartMonth == getEndMonth)
{
if(getStartDay < getEndDay)
{
while(getStartDay <= getEndDay)
{
Calendar cal = Calendar.getInstance();
cal.set( getYear, getStartMonth, getStartDay);
Date queryStart = getStartOfDay(cal.getTime());
Date queryEnd = getEndOfDay(cal.getTime());
List<Object[]> res = getSumList(queryStart, queryEnd);
doQuery(res);
++getStartDay;
}
}
else
{
}
}
else
{
}
}
else
{
}
}
Here is what getSumList looks like:
public List<Object[]> getSumList(Date start, Date end) {
String query = "";
query += "SELECT COUNT(s) pCount,"
+ "p.nameText,"
+ "g.nameText,"
+ "t.shiftID"
+ " FROM Sheets s , GradeNames g , SpecieNames p, ShiftTimes t"
+ " WHERE s.createdLocal > :start and s.createdLocal < :end"
+ " AND s.specieNameIndex = p.nameIndex "
+ " AND s.gradeNameIndex = g.nameIndex"
+ " AND s.shiftIndex = t.shiftIndex"
+ " GROUP BY p.nameText , g.nameText , t.shiftID";
Query q = em.createQuery(query);
q.setParameter("start", start);
q.setParameter("end", end);
return q.getResultList();
}
This next function doesn't matter at this point because nothing is being executed because the list length is zero:
private void doQuery(List<Object[]> obj)
{
int length = obj.size();
String grade = null;
Long standingCount = (long) 0;
System.out.println("Length" + length);
for (int i = 0; i < length; ++i) {
// HAVE A LIST OF ALL ITEMS PULLED FROM DATABASE
Object[] tmpObj = obj.get(i);
Long tmpCount = (Long) tmpObj[0];
String tmpSpecieName = (String) tmpObj[1];
Double tmpThickness = Double.parseDouble(getSpecie().getThicknessFromSpecie(tmpSpecieName));
String tmpLength = getSpecie().getLengthFromSpecie(tmpSpecieName);
String tmpGradeName = (String) tmpObj[2];
String tmpShift = (String) tmpObj[3];
tmpSpecieName = getSpecie().getSpecieFromSpecie(tmpSpecieName);
//// END OF ALL ITEMS PULLED FROM DATABASE
if (grade != pullGradeName(tmpGradeName) && grade != null) {
System.out.println("Count:" + standingCount + "Grade:" + tmpGradeName + "--" + "Specie" + tmpSpecieName + "Shift:" + tmpShift + "Thickness:" + tmpThickness + "Length:" + tmpLength + "SpecieNAme:" + tmpSpecieName);
// do previous insert
grade = pullGradeName(tmpGradeName);
} else if (grade != pullGradeName(tmpGradeName) && grade == null) {
grade = pullGradeName(tmpGradeName);
} else if (grade == pullGradeName(tmpGradeName)) {
standingCount = standingCount + tmpCount;
}
System.out.println("Count:" + tmpCount + "Grade:" + tmpGradeName + "--" + "Specie" + tmpSpecieName + "Shift:" + tmpShift + "Thickness:" + tmpThickness + "Length:" + tmpLength + "SpecieNAme:" + tmpSpecieName);
}
}
Check the SQL that is generated, and the tables you are querying over. As the query requires inner joins, if one of the tables was cleared, it would return no results. If you want to get a 0 count, you need to use an outer join syntax which isn't possible in JPA unless you use object level mappings:
"SELECT COUNT(s) pCount,"
+ "p.nameText,"
+ "g.nameText,"
+ "t.shiftID"
+ " FROM Sheets s outer join s.specialNameIndex p,"
+ " outer join s.gradeNameIndex g, outer join s.shiftIndex t"
+ " WHERE s.createdLocal > :start and s.createdLocal < :end"
+ " GROUP BY p.nameText , g.nameText , t.shiftID";

return array from inside an if,for statement

I am building a tag reader for inventory purpose. Using the for loop to iterate through the tags to count/total the ids. I get an error on my return line "tagsFound cannot be resolved into a variable". How do i use the variable inside the for loop and then access it outside the loop?
public String[] getTags(AlienClass1Reader reader)throws AlienReaderException{
int coneCount = 0;
int drumCount = 0;
// Open a connection to the reader
reader.open();
// Ask the reader to read tags and print them
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found: " + tagList.length);
for (int i=0; i<tagList.length; i++) {
Tag tag = tagList[i];
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
//tagFound[i]= "" + tag.getTagID();
String phrase = tag.getTagID();
tagFound[i] = phrase;
String delims = "[ ]+";
String[] tokens = phrase.split(delims);
if (tokens[0].equals("0CCE") && tokens[3].equals("1001")){drumCount++;}
if (tokens[0].equals("0CCE") && tokens[3].equals("1004")){coneCount++;}
String[] tagsFound;
tagsFound[i] = tag.getTagID();
}
System.out.println("Cones= " + coneCount);
System.out.println("Drums= " + drumCount);
// Close the connection
reader.close();
return tagsFound;
}
}
public String[] getTags(AlienClass1Reader reader)throws AlienReaderException{
int coneCount = 0;
int drumCount = 0;
// Open a connection to the reader
reader.open();
// Ask the reader to read tags and print them
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found: " + tagList.length);
String[] tagsFound = new String[tagList.length];
for (int i=0; i<tagList.length; i++) {
tagsFound = "";
Tag tag = tagList[i];
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
//tagFound[i]= "" + tag.getTagID();
String phrase = tag.getTagID();
tagFound[i] = phrase;
String delims = "[ ]+";
String[] tokens = phrase.split(delims);
if (tokens[0].equals("0CCE") && tokens[3].equals("1001")){drumCount++;}
if (tokens[0].equals("0CCE") && tokens[3].equals("1004")){coneCount++;}
tagsFound[i] = tag.getTagID();
}
System.out.println("Cones= " + coneCount);
System.out.println("Drums= " + drumCount);
// Close the connection
reader.close();
return tagsFound;
}
}
the returned array will have empty strings in the positions where the tag does not satisfy the criteria.

java.lang.ArrayIndexOutOfBoundsException :

I have a String = "abc model 123 abcd1862893007509396 abcd2862893007509404", if I provide space between abcd1 & number eg. abcd1 862893007509396 my code will work fine, but if there is no space like abcd1862893007509396, I will get java.lang.ArrayIndexOutOfBoundsException, please help ?:
PFB the code :
String text = "";
final String suppliedKeyword = "abc model 123 abcd1862893007509396 abcd2862893007509404";
String[] keywordarray = null;
String[] keywordarray2 = null;
String modelname = "";
String[] strIMEI = null;
if ( StringUtils.containsIgnoreCase( suppliedKeyword,"model")) {
keywordarray = suppliedKeyword.split("(?i)model");
if (StringUtils.containsIgnoreCase(keywordarray[1], "abcd")) {
keywordarray2 = keywordarray[1].split("(?i)abcd");
modelname = keywordarray2[0].trim();
if (keywordarray[1].trim().contains(" ")) {
strIMEI = keywordarray[1].split(" ");
for (int i = 0; i < strIMEI.length; i++) {
if (StringUtils.containsIgnoreCase(strIMEI[i],"abcd")) {
text = text + " " + strIMEI[i] + " "
+ strIMEI[i + 1];
System.out.println(text);
}
}
} else {
text = keywordarray2[1];
}
}
}
After looking at your code the only thing i can consider for cause of error is
if (StringUtils.containsIgnoreCase(strIMEI[i],"abcd")) {
text = text + " " + strIMEI[i] + " "
+ strIMEI[i + 1];
System.out.println(text);
}
You are trying to access strIMEI[i+1] which will throw an error if your last element in strIMEI contains "abcd".

Categories

Resources