-1

android 응용 프로그램에서 마이크로 프로세서에 ble를 쓰려고하는데 이상한 일이 일어나고 있습니다. 나는 쓰기를 시도하고있는 특성이 발견되지 않는 것으로 나타났습니다 약간의 디버깅 후writeCharacteristic에서 null 포인터 예외가 발생했습니다.

Unhandled exception in callback 
                        java.lang.NullPointerException 
                         at android.bluetooth.BluetoothGatt.writeCharacteristic(BluetoothGatt.java:874) 
                         at com.example.tannerhenry.standalone.ConfigurationActivity.setWriteSensor(ConfigurationActivity.java:248) 
                         at com.example.tannerhenry.standalone.ConfigurationActivity.access$100(ConfigurationActivity.java:31) 
                         at com.example.tannerhenry.standalone.ConfigurationActivity$4.onServicesDiscovered(ConfigurationActivity.java:289) 
                         at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:295) 
                         at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:215) 
                         at android.os.Binder.execTransact(Binder.java:404) 
                         at dalvik.system.NativeStart.run(Native Method) 

때문에 이유를 설명 :

오류에 대한 로그는 다음과 같습니다, 시작하려면 널 포인터 예외가 발생합니다.

문제는입니다. 내 iPhone에 LightBlue를 다운로드했기 때문에 특성이 분명히 광고되고 특성이 나타납니다. 이것은 내가 특성을 초기화하는 데 실수를했다고 믿게하는데, 나는 앱 스토어에서 블루투스 LE 스캐너를 다운로드 한 후에도 내 앱과 같은 방식으로 작동한다.

iOS 및 Android getCharacteristics의 방식에 차이가 있습니까?

참고 : 이전에이 문제가 있었지만 솔루션에서 앱을 몇 번 다시 다운로드하고 결국 특성을 읽었습니다. 그러나 타블렛에서 데이터를 지우고 이전과 똑같은 일을하고 있으며 이번에는 다시 다운로드하지 않습니다.

도움을 주시면 감사하겠습니다. 필요한 경우 더 많은 코드를 제공해 드리겠습니다.

+0

자신 만의 BluetoothGattCharacteristic 개체를 만들지 말고 먼저 gatt.discoverServices()를 수행 한 다음 onServicesDiscovered 콜백에서 gatt.getService (uuid) 또는 gatt.getServices()를 사용하여 서비스를 가져와야합니다. 그런 다음 service.getCharacteristic (uuid) 또는 service.getCharacteristics()를 사용하여 BluetoothGattCharacteristic 객체를 가져올 수 있습니다. – Emil

+0

예 내 onConnectionStateChange 콜백의 연결 상태에서 gatt.discoverServices를 호출하므로 문제가되지 않습니다. 내가 서비스에 넣을 수있는 특징이 얼마나되는지 아십니까? @Emil – thenry

+0

gatt db가 0xffff 개 이상의 핸들을 가질 수 있다는 점을 제외하고는 아무런 제한이 없습니다. – Emil

답변

0

이전에 페어링 된 장치를 수동으로 잊어 버리고 복구하여 문제가 해결되었습니다.

관련 문제