java - ArrayIndexOutOfBoundException when displaying matched lines -
java - ArrayIndexOutOfBoundException when displaying matched lines -
i have issue in android code. objective of code read each lines of text file match static string need display matched questions. static input string "what dob" , having text(fms.txt) file has questions in assets folder. have compiled code. got output errors.
my code
try { ins = this.getassets().open("fms.txt"); reader = new bufferedreader(new inputstreamreader(ins)); line = reader.readline(); message = "what dob"; messages = message.split(" "); int = 0, j = 0, inc = 1, oldin = 0; while (line != null) { lines = line.split("#"); words = lines[0].split(" "); if (words[0].trim().equals(messages[0].trim())) { for(i = 1; messages[i].trim() != null; i++) { log.e(tag, "----------::::"+messages[i].trim()); oldin = inc; } } line = reader.readline(); } ins.close(); log.e(tag, "---------fmsg : "+finalmsg); } catch(ioexception e1) { e.printstacktrace(); }
you facing here arrayindexoutofboundsexception because still have somewhere white space in comparision
replace
for(i=1; messages[i] != null, i++)
with
for(i = 1; < messages.length && messages[i] != null && !messages[i].trim().isempty(); i++)
java
Comments
Post a Comment