
April 18th, 2011, 06:03 AM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 1
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 |
|
|
|
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()); 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(); os.write("1".getBytes()); print+=" Stampato"; os.close(); is.close(); tmpsock.close(); // TODO Auto-generated catch block e.printStackTrace(); print+="Security"; // TODO Auto-generated catch block print+="NoSuchMethodException"; e.printStackTrace(); // TODO Auto-generated catch block e.printStackTrace(); print+="IllegalArgumentException"; // TODO Auto-generated catch block e.printStackTrace(); print+="InvocationTargetException"; // TODO Auto-generated catch block e.printStackTrace(); print+="IllegalAccessException"; // 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 09:33 PM.
|