안녕하세요.
BluetoothChat 소스를 이용하여 블루투스 페어링 부분을 참고 있는데요.
블루투스가 활성화된 디바이스를 검색한 다음 리스트뷰에 검색된 디바이스를 선택하면 검색하는 디바이스가 죽어버리네요.
BluetoothChat에 있는 BluetoothChatService, DeviceListActivity 파일은 그대로 사용하고 BluetoothChat 파일만 제가
수정하였습니다. 에러 로그는 마지막에 있습니다.
또 궁금한게 블루투스 페어링을 하기 위해서는 연결될 디바이스가 자기를 찾을 수 있게 discoverable을 해주고
다른 디바이스가 discovery를 해서 그 기기를 찾고
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try {
BluetoothDevice device = bluetooth
.getRemoteDevice("00:19:01:40:19:C3");
BluetoothSocket clientSocket = device
.createRfcommSocketToServiceRecord(uuid);
clientSocket.connect();
} catch (IOException e) {
Log.d("BLUTOOTH", e.getMessage());
}
이런식으로 블루투스 소켓열어서 연결시켜주는 방법이 맞는 것인지요??
간단하게 위 소스 참고해서 페어링 시켜보려다 안되서 bluetoothchat 예제 이용해서 한번 해보려고 하는데..
잘안되네요. 답변 주시면 진심으로 감사하겠습니다.
01-19 20:02:21.237 E/AndroidRuntime( 3697): FATAL EXCEPTION: main
01-19 20:02:21.237 E/AndroidRuntime( 3697): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { (has extras) }} to activity {my.com.nfc/my.com.nfc.PairingBluetooth}: java.lang.NullPointerException
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3019)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread.access$1100(ActivityThread.java:122)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1176)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.os.Looper.loop(Looper.java:137)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at java.lang.reflect.Method.invoke(Method.java:511)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at dalvik.system.NativeStart.main(Native Method)
01-19 20:02:21.237 E/AndroidRuntime( 3697): Caused by: java.lang.NullPointerException
01-19 20:02:21.237 E/AndroidRuntime( 3697): at my.com.nfc.PairingBluetooth.connectDevice(PairingBluetooth.java:264)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at my.com.nfc.PairingBluetooth.onActivityResult(PairingBluetooth.java:235)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.Activity.dispatchActivityResult(Activity.java:4651)
01-19 20:02:21.237 E/AndroidRuntime( 3697): at android.app.ActivityThread.deliverResults(ActivityThread.java:2972)
01-19 20:02:21.237 E/AndroidRuntime( 3697): ... 11 more
01-19 20:02:21.287 W/ActivityManager( 400): Force finishing activity my.com.nfc/.PairingBluetooth




PairingBluetooth.java의 264줄에서 널포인트에러가 나네요. 그부분 소스도 보여주실수 있으면 보여주세요 ^^;;
01-19 20:02:21.237 E/AndroidRuntime( 3697): Caused by: java.lang.NullPointerException
01-19 20:02:21.237 E/AndroidRuntime( 3697): at my.com.nfc.PairingBluetooth.connectDevice(PairingBluetooth.java:264)