nitingautam / smslib

Automatically exported from code.google.com/p/smslib
0 stars 0 forks source link

StringIndexOutOfBoundsException [at] ModemGateway.java:541 #373

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
hello, i'm a new user for this lib and has been using it for the last 2 days... 
so i try to connect my SonyErricsson w660 phone with it and find out that 
everytime i try to do ReadMessage function i get this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1943)
        at org.smslib.modem.ModemGateway.readMessagesPDU(ModemGateway.java:541)

i've been tracking through issues to find the solution, there are some 
"similar" issues and try it but no luck. so i try to solve this myself and 
rebuild the library by adding 1(one) line command at the ModemGateway.java and 
it works...well here it is:

...
while (true)
                {
                    if (line == null) break;
                    line = line.trim();
                    if (line.length() <= 0 || line.equalsIgnoreCase("OK")) break;
                    if (line.length() <= 0 || line.equalsIgnoreCase("ERROR")) break;
                    i = line.indexOf(':');
                    j = line.indexOf(',');
                    memIndex = 0;
                    try
                    {
                        memIndex = Integer.parseInt(line.substring(i+1, j).trim());
                    }
                    catch (NumberFormatException e)
                    {
                        // TODO: What to do here?
                        getService().getLogger().logWarn("Incorrect Memory Index number parsed!", e, getGatewayId());
                    }

after this line I add this:

catch (StringIndexOutOfBoundsException se) {
                                            System.out.println("exception swallowed");
                                        }

it happen when the program through with memIndex reading and gets the pduString 
instead and try to split the string with i and j contain -1 so that's why i 
think we need to catch the exception then continue to the next line.
sorry for the bad english...
regards.

Original issue reported on code.google.com by grunge...@gmail.com on 5 Jul 2010 at 3:54

GoogleCodeExporter commented 9 years ago
Can you please upload a log from the ReadMessage sample?

You shouldn't get any exception, unless your phone's response is a bit 
different than expected...

Original comment by T.Delenikas on 17 Jul 2010 at 9:15

GoogleCodeExporter commented 9 years ago
sorry, i can't get the logging system to work...i'll send it later...thanks :D

Original comment by grunge...@gmail.com on 20 Jul 2010 at 1:13

GoogleCodeExporter commented 9 years ago
No feedback.

Original comment by T.Delenikas on 12 Aug 2010 at 5:57