android - Need some explaining -


so weirdest thing ever happen me during programing. yes im no pro @ programing im learning go. ive got app talking server, socket in main thread, reading done in separate class , thread , writing in separate class asynctask.

the problem locationmanager. talk server , write/read commands fine, implemented locationmanager , listener.

i proceeded implement method update textview new coordinates on locatinchanged. far good. thing when use emulator control in eclipse , send coordinates app crashed stringoutofboundsexception (ive programed 3 years never seen this). looked @ code stepped through , on. read stacktrace, logcat, console , everywhere think of got me nowhere. until went readerthread wich looks this:

    public class readerthread extends thread {     public void run() {         new thread(new runnable(){             public void run(){                                   try {                     //establish bufferedreader read socket/server.                     in = new bufferedreader(new inputstreamreader(socket.getinputstream()), 8 * 1024);             }              catch(exception e) { e.printstacktrace(); }          //as long connect true.                while (connected) {             string line;             try {                 //try read line reader.                 line = in.readline();                 system.out.println(in.readline());                 if (in == null) {                     //no 1 has sent message yet.                     system.out.println("no data recieved");                 }                  else {                     int = 0;                     //as long sending messages.                     while((line = in.readline()) != null ){                          //make new message.                         message msg;                         msg = new message();                         //set object input line.                         msg.obj = line;                         //set id can identified in main class , used in switch.                         msg.what = i;                         system.out.println("i is: "+i);                         //send message handler.                         main.this.h.sendmessage(msg);                        }                 }             }             catch (exception e) {                 system.out.println(e.getmessage());             }         }              }                    }).start();      } 

the variable in if statement depending on server sent cut out has nothing problem.

the problem freaking catch. when catch ioexception, app crashes. out of dumb luck changed exception , printed e.message catch error , see caused it. thing change fixed it. how can switching ioexception plain exception fix problem this?

its ioexception program says: "hey not gonna catch error there no error" exception says "well catch ill proceed".

my app working cant grasp this, why , how happen?

you're telling application catch base exception class. means type of error caught, since exception classes descend base type. since stringoutofboundsexception not descend ioexception not being caught before , error not being caught. instead of catching exceptions, might try following:

try {     // code here... } catch (ioexception e) {     log.e(tag, "caught ioexception!", e); } catch (stringoutofboundsexception e) {     log.e(tag, "caught string out of bounds exception!", e); } 

i'm unable determine throwing stringoutofboundsexception begin with. may in if statement cut out of example.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -