3

I have an app that works well on many Android devices, but there is a problem on the BlackBerry Android player running on the PlayBook (it runs Android 2.3).

I had a NumberFormatException on PreferenceManager.getDefaultSharedPreferences(). It appeared that in the preferences file, a float was saved as "@.0E-12". I made this simple test:

float f = 1.0e-12f;
System.out.println (f); // prints "@.0E-12" on BlackBerry PlayBook !!

How can this be?

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
Patrick
  • 3,578
  • 5
  • 31
  • 53

2 Answers2

0

its a very small number (i.e. 0.000000..01).
if it means anything to you you can try BigDecimal.
otherwise you can decide that numbers that are smaller than x (you decide how small the x is) are 0.

Royi
  • 745
  • 8
  • 22
  • I have to use float (not BigDecimal) to save Android settings in SharedPreferences. It works perfectly on all Android systems, except on the PlayBook. And the number is not that small. – Patrick Apr 17 '13 at 07:37
0

If your question is How can this be?, I think you can download the Android source, find relevant sources in libcore/luni/src/main/java/java/lang, and, starting from Float.toString(), begin to import function by function to your project, checking each time that the bug is still seen. You will locate the bug, it is likely something related to FP math. (Maybe, something like random bits in the least significant part of mantissa.)

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • This is not a problem with Android (it works on all the emulators) but only with the PlayBook Android player. – Patrick Apr 17 '13 at 07:45
  • I mean that you could locate a place in the code that works on all platforms except of the PlayBook Android player. Then, it is either a Java bug (it may rely on something undocumented that just happens to work on most platforms), or a Java VM bug, or a bug of that particular hardware. Of course, if you are really interested in _how can that happen?_ – 18446744073709551615 Apr 17 '13 at 08:19
  • I think you don't need the Blackberry source, the code from Google will do. It is very unlikely that the Blackberry team took known-to-be-good code and introduced a bug into it, first of all because there is no profit in modifying these java.lang classes. Most likely, the code is the same as the code in the Android source distribution, so you will see the underlying problem even with the open-sourced original code. (But even if they did introduce a bug, which is unlikely, you will know which function gives that incorrect result.) – 18446744073709551615 Apr 17 '13 at 10:13