araobp / sensor-network-android

Wired sensor network for IoT with PIC16F1 and Android
0 stars 1 forks source link

System crashes when data is from Hall Sensor #1

Closed araobp closed 7 years ago

araobp commented 7 years ago

Code

class DriverSimulatorServiceImpl: SensorNetworkService() {

    private var mValue = 300
    private var mSleep = TIMER * mValue

    override fun onCreate() {
        super.onCreate()

        mSleep = TIMER * mValue
        try {
            thread(start = true) {
                while (true) {
                    if (driverStatus.opened && driverStatus.started) {
                        try {
                            Thread.sleep(mSleep.toLong())
                        } catch (e: InterruptedException) {
                            Log.e(TAG, e.toString())
                        }
                        rx("%19:FLOAT:-0.01,0.03,-0.01") <== ok
                        //rx("%17:UINT8_T:0")  <== crash
                    }
                }
            }
        } catch (e: Exception) {
            Log.e(TAG, e.toString())
        }
    }

Android monitor

08-12 13:04:10.779 9534-9572/jp.araobp.iot.cli D/Cycling: SensorData(timestamp=1502543050779, rawData=%17:UINT8_T:0, deviceId=17, type=UINT8_T, data=[0], schedulerInfo=null)

                                                          --------- beginning of crash
08-12 13:04:10.780 9534-9572/jp.araobp.iot.cli E/AndroidRuntime: FATAL EXCEPTION: Thread-4
                                                                 Process: jp.araobp.iot.cli, PID: 9534
                                                                 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
                                                                     at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:363)
                                                                     at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
                                                                     at jp.araobp.iot.edge_computing.EdgeComputing$1.invoke(EdgeComputing.kt:20)
                                                                     at jp.araobp.iot.edge_computing.EdgeComputing$1.invoke(EdgeComputing.kt:11)
                                                                     at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:18)
araobp commented 7 years ago

fixed