Android Bluetooth Socket not created -


my app trying connect bluetooth module , send/receive data simultaneously. following error thrown (it happens after gc call):-

12-15 19:06:15.559: d/dalvikvm(22875): gc_for_alloc freed 3925k, 25% free 11400k/15096k, paused 28ms, total 28ms     12-15 19:06:15.559: e/system(22875): uncaught exception thrown finalizer  12-15 19:06:15.559: e/system(22875): java.io.ioexception: socket not created     12-15 19:06:15.559: e/system(22875):    @ android.net.localsocketimpl.shutdowninput(localsocketimpl.java:392) 12-15 19:06:15.559: e/system(22875):    @ android.net.localsocket.shutdowninput(localsocket.java:206) 12-15 19:06:15.559: e/system(22875):    @ android.bluetooth.bluetoothsocket.close(bluetoothsocket.java:462) 12-15 19:06:15.559: e/system(22875):    @ android.bluetooth.bluetoothsocket.finalize(bluetoothsocket.java:229) 12-15 19:06:15.559: e/system(22875):    @ java.lang.daemons$finalizerdaemon.dofinalize(daemons.java:187) 12-15 19:06:15.559: e/system(22875):    @ java.lang.daemons$finalizerdaemon.run(daemons.java:170) 12-15 19:06:15.559: e/system(22875):    @ java.lang.thread.run(thread.java:841) 

this uncaught exception thrown repeatedly few number of times , result app stop responding.

what can possible reasons error? trying solve can't find exact issue. please help.

i attaching code using connect bluetooth module. using asynctask this..

    //global variable     bluetoothsocket mbsocket;      // inside doinbackground() function     mbluetoothadapter = bluetoothadapter.getdefaultadapter();     if (mbluetoothadapter.isenabled()) {         try {             (bluetoothdevice bt : mbluetoothadapter.getbondeddevices()) {                 if (bt.getname().equalsignorecase("my_device_bt_name")) {                     bluetoothdevice device = mbluetoothadapter                             .getremotedevice(bt.getaddress());                     mbluetoothadapter.canceldiscovery(); // have named our                                                             // device                                                             // cancel search                     mbsocket = device                             .createrfcommsockettoservicerecord(spp_uuid);                     if(!mbsocket.isconnected()) {                         mbsocket.connect();                     }                     return mbsocket;                 }             }             return null;         } catch (ioexception e) {             e.printstacktrace();             return null;         }      } else         return null; 

i have modified code connect bluetooth module, handled exceptions properly, since there isn't such error facing have described in question.

//global variable bluetoothsocket mbsocket;  // inside doinbackground() function mbluetoothadapter = bluetoothadapter.getdefaultadapter(); if(mbluetoothadapter.isenabled()) {     try {         for(bluetoothdevice bt: mbluetoothadapter.getbondeddevices()) {             if(bt.getname().equalsignorecase(params[0])) {                 bluetoothdevice device = mbluetoothadapter.getremotedevice(bt.getaddress());                 mbluetoothadapter.canceldiscovery();                  mbsocket = device.createrfcommsockettoservicerecord(spp_uuid);                 mbsocket.connect();                 return mbsocket;             }         }     } catch(ioexception e) {         if(mbsocket != null) {             try {                 mbsocket.close();             } catch (ioexception e1) {                 e1.printstacktrace();             }             mbsocket = null;         }         e.printstacktrace();         return null;     } }  return null; 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -