#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    RFCOMM InvocationTargetException


    Hi, I'm trying to create an application using a bluetooth rfcomm channel.

    But I get the exception InvocationTargetException.

    The code that executes is the following:

    java Code:
    public class Start extends Activity {
        private static final int REQUEST_ENABLE_BT = 2;
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView t=new TextView(this.getApplicationContext());
            String print="";
            BluetoothAdapter adapter = null;
            adapter = BluetoothAdapter.getDefaultAdapter();
     
            //abilito il bluetooth se questo non lo 
             if (!adapter.isEnabled()) {
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
     
            }
            BluetoothDevice device = adapter.getRemoteDevice("00:17:A0:01:56:9C");
            print+=" "+device.getAddress();
            BluetoothSocket tmpsock = null;
            int port=1;
     
            try {
                Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
                tmpsock = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
                tmpsock.connect();
                InputStream is=tmpsock.getInputStream();
                OutputStream os=tmpsock.getOutputStream();
                os.write("1".getBytes());
                print+=" Stampato";
                os.close();
                is.close();
                tmpsock.close();
     
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                print+="Security";
     
            } catch (NoSuchMethodException e) {
                // TODO Auto-generated catch block
                print+="NoSuchMethodException";
                e.printStackTrace();
     
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                print+="IllegalArgumentException";
     
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                print+="InvocationTargetException";
     
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                print+="IllegalAccessException";
     
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                print+="IOException";
     
            } finally {
                t.setText(print);
                this.setContentView(t);
     
            }
     
        }
     
    }


    Someone can help me. Thanks

    Moderated by Nilpo: fixed code layout
    Last edited by Nilpo; May 16th, 2011 at 10:33 PM.

IMN logo majestic logo threadwatch logo seochat tools logo