마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

블루투스가 페어링 이후 어플이 다운됩니다.

0 추천

컴퓨터와 페어링 이후 activity가 죽어 버립니다.

로그를 봐도 딱히 뭐가 잘못인지 모르겠고요.

 
[connectedThread]        
public void run() {
            Log.i(debug_name, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes = 0;

            // Keep listening to the InputStream while connected
            while (true) { // 죽는 부분, 주석으로 처리 해도 죽습니다.
                try {
                    // Read from the InputStream
                    bytes = in.read(buffer);   

                    // Send the obtained bytes to the UI Activity
                    handler.obtainMessage(MESSAGE.READ.valueOf(), bytes, -1, buffer).sendToTarget();
                } catch (IOException e) {
                    Log.e(debug_name, "disconnected", e);
                    connectionLost();
                    break;
                }
            }
        }

 

코드를 보시면 아시겠지만 그냥 흔하게 돌아 다니는 예제 코드에서 수정을 하고 있습니다.

아무튼 혹시 이런 경우 어떻게 디버깅을 해야 하는 건가요?
제가 디버깅을 정말 못해서 ㅠㅠ 그러는데 어디서부터 체크를 해야 하는지 조언 해주실 수 있나요?
 
처음엔 InputStream이 null 이거나 handler가 null 이어서 그런 줄 알았는데 아니더군요.
 
지금 수정 방향은 블루투스가 activity와는 관계 없이 별도록 돌수 있도록 하는 것인데,
어찌어찌 해서 페어링까진 했는데 그 이후 connectedThread 에서 계속 죽네요.
 
 
아무튼 어디부터 차근히 바야 할까요? UUID도 처음에 잘못 넣어서 안되던것 수정도 했습니다.
 
[로그는 덧글로 첨부하겠습니다.]
 
로그도 무엇을 봐서 어떻게 접근해야 하는지 잘 모르겠고요.
답은 아니더라도 이런 경우 어떻게 접근을 해야 하는지 조언 해주실 수 있나요?
 
지금 제가 못 찾는게 제소스에서 에러나서 죽는거면 주석처리했을 경우 문제가 없어야 하는데...
저 부분에서 계속해서 죽는데도 불구하고 저 부분을 주석처리해도 해결되지 않는 다는 겁니다.
 
그래서 더 못찾고 있습니다. ㅠㅠ

 

미친공대생 (270 포인트) 님이 2015년 8월 18일 질문
08-18 09:43:47.031: D/BluetoothService(8537): connected
08-18 09:43:47.031: D/BluetoothService(8537): Securecancel Thread[AcceptThreadSecure,5,main]
08-18 09:43:47.031: D/BluetoothSocket(8537): close() in, this: android.bluetooth.BluetoothSocket@186e61fb, channel: 6, state: LISTENING
08-18 09:43:47.031: D/BluetoothSocket(8537): close() this: android.bluetooth.BluetoothSocket@186e61fb, channel: 6, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@88a9e38, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@bfc6218mSocket: android.net.LocalSocket@36e94471 impl:android.net.LocalSocketImpl@1492c256 fd:FileDescriptor[49]
08-18 09:43:47.031: D/BluetoothSocket(8537): Closing mSocket: android.net.LocalSocket@36e94471 impl:android.net.LocalSocketImpl@1492c256 fd:FileDescriptor[49]
08-18 09:43:47.036: D/BluetoothService(8537): Insecurecancel Thread[AcceptThreadInsecure,5,main]
08-18 09:43:47.036: D/BluetoothSocket(8537): close() in, this: android.bluetooth.BluetoothSocket@1e3722d7, channel: 7, state: LISTENING
08-18 09:43:47.036: D/BluetoothSocket(8537): close() this: android.bluetooth.BluetoothSocket@1e3722d7, channel: 7, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@754ab76, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@336187c4mSocket: android.net.LocalSocket@1d7cb6ad impl:android.net.LocalSocketImpl@490ade2 fd:FileDescriptor[50]
08-18 09:43:47.036: D/BluetoothSocket(8537): Closing mSocket: android.net.LocalSocket@1d7cb6ad impl:android.net.LocalSocketImpl@490ade2 fd:FileDescriptor[50]
08-18 09:43:47.041: E/BluetoothService(8537): Secureaccept() failed
08-18 09:43:47.041: E/BluetoothService(8537): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:637)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:614)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:514)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:130)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:116)
08-18 09:43:47.041: E/BluetoothService(8537):  at com.gloins.service.bluetooth.BluetoothService$AcceptThread.run(BluetoothService.java:358)
08-18 09:43:47.041: E/BluetoothService(8537): Insecureaccept() failed
08-18 09:43:47.041: E/BluetoothService(8537): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:637)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:614)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:514)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:130)
08-18 09:43:47.041: E/BluetoothService(8537):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:116)
08-18 09:43:47.041: E/BluetoothService(8537):  at com.gloins.service.bluetooth.BluetoothService$AcceptThread.run(BluetoothService.java:358)
08-18 09:43:47.041: I/BluetoothService(8537): END mAcceptThread, socket Type: Insecure
08-18 09:43:47.046: I/BluetoothService(8537): END mAcceptThread, socket Type: Secure
08-18 09:43:47.071: D/BluetoothService(8537): create ConnectedThread :Insecure
08-18 09:43:47.081: I/BluetoothService(8537): BEGIN mConnectedThread
08-18 09:43:51.351: D/BluetoothService(8537): setState() CONNECTED -> CONNECTED
08-18 09:43:51.356: I/BluetoothServer(8537): MESSAGE_STATE_CHANGE: 3
08-18 09:43:54.436: D/AndroidRuntime(8537): Shutting down VM
08-18 09:43:54.436: E/AndroidRuntime(8537): FATAL EXCEPTION: main
08-18 09:43:54.436: E/AndroidRuntime(8537): Process: com.gloins.bti, PID: 8537
08-18 09:43:54.436: E/AndroidRuntime(8537): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ArrayAdapter.clear()' on a null object reference
08-18 09:43:54.436: E/AndroidRuntime(8537):  at com.gloins.service.bluetooth.BluetoothServer$1.handleMessage(BluetoothServer.java:400)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at android.os.Handler.dispatchMessage(Handler.java:102)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at android.os.Looper.loop(Looper.java:145)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at android.app.ActivityThread.main(ActivityThread.java:5972)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at java.lang.reflect.Method.invoke(Native Method)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at java.lang.reflect.Method.invoke(Method.java:372)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
08-18 09:43:54.436: E/AndroidRuntime(8537):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
그리고 어플이 죽을 때 나오는 팝업창은 unfortunately, example has stopped 입니다. log에도 NullPointerException 이라고 나와서 어딘가 null이구나 했는데 제가 찾아 보니깐 null 값은 없던데요. thread도 돌고 있고 하던데요.
ArrayAdapter도 확인해보셨나요?
ArrayAdapter라 하심은 검색된 장치의 리스트를 말씀 하시는 것 같은데요. 그건 확인했습니다. 그리고 선택해서 pairing을 한걸 봐선 adapter에서 값의 반환은 되긴 한것 같습니다.

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...