empatica / empalink-sample-project-android

An Android sample project for the Empatica API
BSD 3-Clause "New" or "Revised" License
41 stars 24 forks source link

NumberFormatException: Invalid int: "So" #5

Closed LsVzqz closed 4 years ago

LsVzqz commented 8 years ago

All,

I will "randomly" get an exception and maybe it's something within EmpaLinkBLE.java line 345. Here is the stack trace from the Android Monitor.

11-02 22:52:34.725 1764-1813/? D/bt_btif_gattc: btif_gattc_update_properties BLE device name=Bose Color II SoundLink len=23 dev_type=3 11-02 22:52:34.735 20441-20441/com.qualcomm.snapdragon.sdk.sample D/AndroidRuntime: Shutting down VM 11-02 22:52:34.736 20441-20441/com.qualcomm.snapdragon.sdk.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.qualcomm.snapdragon.sdk.sample, PID: 20441 java.lang.NumberFormatException: Invalid int: "So" at java.lang.Integer.invalidInt(Integer.java:138) at java.lang.Integer.parse(Integer.java:410) at java.lang.Integer.parseInt(Integer.java:367) at java.lang.Integer.parseInt(Integer.java:334) at com.empatica.empalink.EmpaLinkBLE$2.onLeScan(EmpaLinkBLE.java:345) at android.bluetooth.BluetoothAdapter$2.onScanResult(BluetoothAdapter.java:2215) at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run(BluetoothLeScanner.java:355) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

hyorkim11 commented 8 years ago

awesome to see more people developing on the Empatica!

there is only so much we can do without the source code, but here it goes:

first you want to look at where the initial exception is thrown. biggest clue would be the the java.lang.NumberFormatException: Invalid int: "So" I'm guessing you're trying to parse a variable as an int, and it's confused because it received a String.

Wherever you're "processing" this variable I would throw in a try/catch for proper error handling.

And check this out for possible references.

Good Luck!

LsVzqz commented 8 years ago

Hello hyorkim11.

That's the thing. I think the code within empalink is the one that needs some type of try/catch block. I don't believe that source code is available (if so, guess I can try poking around in there).

Using Android Studio, it tries to decompile some of the .class files. Obviously, the variable names aren't too helpful in this view, but searching for parseInt, I think the problem is when it tries to get substrings of the deviceInfo object. I only see fields labeled a, b, c, d, but I figure in the actual code, they are labeled differently.

For some reason, one of the sub strings, which I'm guessing is deviceInfo.c = Integer.parseInt(empaLabel.substring(0, 2)); is pulling back a "So" instead of a number.

I haven't seen this error until a few days ago, and for the record, I haven't turned on my Empatica E4 in days, so another theory I have is that it's somehow picking up something and thinking it's an Empatica?

--- I actually came back to this unsubmitted reply after I started reviewing the decompiled class file and I'm convinced that the problem is actually tied to this following observation ---

Another thing I find odd (I haven't noticed before) is a reference to that Bose device. I don't own any of those devices. However, it does have 4 tokens in its name delimited by spaces. It is greater than 19 characters (per the empalink code which checks for these two conditions). empaLabel is assigned the last item in the 4 token list (nameParts), which is Sound, and tries to convert the first two characters to a number.

I think there should be a try/catch around those parse ints. This invalid exception is killing my entire android application and since this onscan is happening outside my activity, I don't think I can encapsulate it with a try catch. I wouldn't want to run my study with participants where there may be more random bluetooth devices and run the risk of a force close in front of the participants. I'm starting to ramble due to the late night hour, but look forward to your response!

hyorkim11 commented 8 years ago

Wow... that's crazy, I didn't notice the Bose it's picking up... I'd imagine you've tried resetting the empatica... I can connect you to an empatica developer personally if you need, he's one of the many people behind this crazy thing!

LsVzqz commented 8 years ago

I would very much appreciate that. Seems like it would just be a few lines of code. :)

Thanks in advance!

pregno commented 7 years ago

Hi @SirLuisV, sorry for the delay. Seems that the library is trying to connect to a device that is not an E4, I'm improving the scanning filter for avoid this misbehaviour.

LsVzqz commented 7 years ago

@pregno , thanks for the response.

I'll be looking forward to the update. I want to do some field testing and it would look bad giving the participants a force close within the app.

Thanks again! Keep me updated when the library gets updated.

pregno commented 7 years ago

We have published an update for the empalink (the new version is the 2.1) and an update for the sample project. Let me know if you still have this issue.