Android Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingAndroid Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 18th, 2011, 06:03 AM
joaquin joaquin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 1 joaquin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 40 sec
Reputation 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:
Original - java Code
  1. public class Start extends Activity {
  2.     private static final int REQUEST_ENABLE_BT = 2;
  3.  
  4.     /** Called when the activity is first created. */
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         TextView t=new TextView(this.getApplicationContext());
  9.         String print="";
  10.         BluetoothAdapter adapter = null;
  11.         adapter = BluetoothAdapter.getDefaultAdapter();
  12.  
  13.         //abilito il bluetooth se questo non lo è
  14.          if (!adapter.isEnabled()) {
  15.             Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  16.             startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
  17.  
  18.         }
  19.         BluetoothDevice device = adapter.getRemoteDevice("00:17:A0:01:56:9C");
  20.         print+=" "+device.getAddress();
  21.         BluetoothSocket tmpsock = null;
  22.         int port=1;
  23.  
  24.         try {
  25.             Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
  26.             tmpsock = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
  27.             tmpsock.connect();
  28.             InputStream is=tmpsock.getInputStream();
  29.             OutputStream os=tmpsock.getOutputStream();
  30.             os.write("1".getBytes());
  31.             print+=" Stampato";
  32.             os.close();
  33.             is.close();
  34.             tmpsock.close();
  35.  
  36.         } catch (SecurityException e) {
  37.             // TODO Auto-generated catch block
  38.             e.printStackTrace();
  39.             print+="Security";
  40.  
  41.         } catch (NoSuchMethodException e) {
  42.             // TODO Auto-generated catch block
  43.             print+="NoSuchMethodException";
  44.             e.printStackTrace();
  45.  
  46.         } catch (IllegalArgumentException e) {
  47.             // TODO Auto-generated catch block
  48.             e.printStackTrace();
  49.             print+="IllegalArgumentException";
  50.  
  51.         } catch (InvocationTargetException e) {
  52.             // TODO Auto-generated catch block
  53.             e.printStackTrace();
  54.             print+="InvocationTargetException";
  55.  
  56.         } catch (IllegalAccessException e) {
  57.             // TODO Auto-generated catch block
  58.             e.printStackTrace();
  59.             print+="IllegalAccessException";
  60.  
  61.         } catch (IOException e) {
  62.             // TODO Auto-generated catch block
  63.             e.printStackTrace();
  64.             print+="IOException";
  65.  
  66.         } finally {
  67.             t.setText(print);
  68.             this.setContentView(t);
  69.  
  70.         }
  71.  
  72.     }
  73.  
  74. }


Someone can help me. Thanks

Moderated by Nilpo: fixed code layout

Last edited by Nilpo : May 16th, 2011 at 09:33 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingAndroid Development > RFCOMM InvocationTargetException

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap