I want to get a float from the preferences. This works fine when the user doesn't enter anything, but when entering 8.23 to the box and saving it, the app crashes on the next start.
MainActivity.java:
float hourly_rate;
SharedPreferences userdata;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
userdata = PreferenceManager.getDefaultSharedPreferences(this);
hourly_rate = userdata.getFloat("hourly_rate", 0.0f);
}
Preferences.xml:
<PreferenceCategory
android:title="@string/general_preferences_title">
<EditTextPreference
android:inputType="numberDecimal"
android:key="hourly_rate"
android:title="@string/hourly_rate_title"
android:summary="@string/hourly_rate_summary" />
</PreferenceCategory>
When I remove the getFloat line, the app doesn't force close.