SMSLib throws Exception at readMessagesPDU
Hi all,
while working on a simple SMS receiver project using Huawei modem, i got this Errors:
Exception in thread "SMSLib-AsyncMessageProcessor : " java.lang.StringIndexOutOfBoundsException: String index out of range: -12 at java.lang.String.substring(String.java:1937) at org.smslib.modem.ModemGateway.readMessagesPDU(ModemGateway.java:546) at org.smslib.modem.ModemGateway.readMessages(ModemGateway.java:208) at org.smslib.modem.AModemDriver$AsyncMessageProcessor.run(AModemDriver.java:878)
westernunion new york class=”spacer_” />
i tried my best to get rid of it, but the luck was not with me. so, i decided to go to the brute force method
i extracted the SMSLib source into my project folder. then i started the project.
i found that the problem occurred in file called ModemGateway.java at line 541:
memIndex = Integer.parseInt(line.substring(i + 1, j).trim());
but in fact the problem was not in the line itself, it was a problem with the variable (line). by looking above line 541 we will found two (if) statements as following:
if (line.length() < = 0 || line.equalsIgnoreCase("OK")) break; if (line.length() <= 0 || line.equalsIgnoreCase("ERROR")) break;
those two statements deals with non required lines. i used the Debugger in order to trace possible (line) values and i got the following possibilities:
CMGL: 0,1,,20 CMS ERROR: 321 OK Error
it is pretty clear that the case “CMS ERROR: 321″ is the one that causes the problem since it has not been handled. so i added the following line to the code:
if (line.length() < = 0 || line.contains("CMS ERROR:")) break;
i think that this solves the problem for the time being
all the best
Related posts:
This entry was posted by AL YAMANI on May 28, 2010 at 12:29 am, and is filed under Programming. Follow any responses to this post through RSS 2.0.You can leave a response or trackback from your own site.