Android preferences exception
When I execute the following code:
Preferences.userRoot().nodeExists(strNodeName);
I get an exception :
java.util.prefs.BackingStoreException: Cannot get children names for User Preference Node: /!
Any idea ?
Asked by: Alfred778 | Posted: 20-01-2022
Answer 1
For storing user preferences, you'll want to use android.content.SharedPreferences. A good article describing how to use it can be found here and the ApiDemos sample app has a demo as well.
Answered by: John540 | Posted: 21-02-2022Similar questions
android - Clearing Shared Preferences throws a Null Pointer Exception
I am getting a null pointer exception every time the user selects "logout" (R.Id.logout) from the option menu. I can't figure out what I'm not initialising.
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.settings:
return false;
case R.id.about:
...
android - class cast exception on shared preferences
I got a property, persisted in shared prferences.
there are 2 places refer to it in entire code:
firstRunTimestamp = wmbPreference.getLong(ApplicationData.ParametersInternals.FIRST_RUN_DATE, 0);
editor.putLong(ApplicationData.ParametersInternals.FIRST_RUN_DATE, new Date().getTime());
In my logs I found this exception
"java.lang.ClassCastException: java.lang.String ...
Shared preferences in android null pointer exception
I move from Activity A to Activity B by intent.I am storing some values in shared preferences in Activity B.In activity A oncreate() i am fetching the values of the shared preferences to compare with some conditions however it gives me null pointer exception as expected (As i do not go to Activity B).However i want to write a condition to fetch the data from shared preferences if the value is not null.Can some one please s...
java - Read of Integer in Shared Preferences causes Class Cast exception
I am trying to obtain the corresponding number from a single select setting on Android, and for some reason it tells me in the LogCat that "String cannot be cast to Integer at getInt. When I go in to analyze the value of the sharedPref at the time of mEventLanguageSelection assignment. At that point, it says KEY_LANGUAGE_SELECTION_LIST=2, which I am quite certain means that getInt should return a value of 2. W...
android - Getting error: "bad token exception" while using preferences
I am trying to add a preference page to my application. The preference screen contains two list preferences and one check box.
But when I try to click the list preference, the application crashes. I don't know how to solve this issue. Can anyone please help me....
Source:
package com.emergencyappbgi;
import com.emergencyappbgi.R;
import android.content.SharedPreferences...
java - Shared Preferences Null Pointer Exception
I am working on adding Shared Preferences to my Note taking Android App and I am running into a peculiar null pointer exception. I am currently testing settings for font size and typeface in my app and have been able to successfully save the shared preferences for both but am having trouble with the retrieval part. When the settings are changed, they successfully change the font and font size on a Fragment for the remainde...
android - reading preferences as int throws exception
I'm trying to read the value stored in preferences as Int, its throwing me classcast exception. Here is the code
SharedPreferences prefs = ct.getSharedPreferences("volumepreference", 0);
SharedPreferences.Editor editor = prefs.edit();
int Past_phone_audio_mode = -1;
try
{
Past_phone_audio_mode = prefs.getInt("volumestate", -1);
}
catch(Exception ...
android - Shared Preferences causing null pointer exception when switching fragments
I am working on a fragment based Android app. In this app, it scrapes some information from websites and stores it in SharedPreferences to compare what the user wants to display. So the user enters some map that they are looking for, the app scrapes the web every 12 seconds and if it matches the users' input it sends a notification. Now this works on a timer which is a handler, when you switch fragments, after...
android - Null Pointer Exception on Shared Preferences on a Spinner control
This question already has answers here:
android - Shared preferences null pointer exception on Activity close
This question already has answers here:
user interface - Creating a standard Android preferences dialog
New Android developer here - I'm hoping this is simple.
I want to create a "row-based" prefs dialog, like you see in most standard apps. You know, black background, fading-line separators, bigger/bold label text for each entry, smaller description text, perhaps a checkbox/down arrow.
Is there a standard object in the Android API for this? If not, how do people usually create these?
Changing android widget setup preferences after creation?
Say my app has a widget and I use a configuration screen to do initial app widget setup and set a few preferences.
I want the user to be able to change those settings by simply going into my app's settings screen and clicking an intent preference to open up the same options the user was given when the app was created.
Can I use the same activity as the configuration activity? Will I have to handle it diffe...
Dismiss android preferences dialog on Keyboard ACTION_DONE press
I would like to be able to close the editpreference dialog (as shown here http://twitpic.com/18ttdp) by pressing the 'Done' button on the keyboard.
Currently, pressing 'Done' just dismisses the keyboard but leaves the dialog.
In other parts of my application I use code similar to the following to intercept the 'Done' key press and execute ac...
Multiple instances of the same android widget: Anyway way to have instance specific preferences?
I am creating a simple Android widget with a typical usecase of having many instances of it running at once.
Using the stock preferencesmanager, it seems each instance of the widget shares the same preferences.
Is there any way to not have this happen?
Thanks!
resources - Using icons in Android preferences
I would like some of my preferences to have icons, like the Settings app.
I guess one way of doing this would be to copy all the relevant code and resources from the Settings app, but it seems like overkill for a couple of icons.
Also I don't like the idea of having to duplicate the code and resources in each project that requires settings icons.
Has anyone solved this already with a simpler or res...
android - Get preferences in AppWidget Provider
I seem to be having trouble reading preferences from my AppWidgetProvider class. My code works in an Activity, but it does not in an AppWidgetProvider. Here is the code I am using to read back a boolean:
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean autoreplyon = settings.getBoolean("autoreplyon", false);
However, I get the "The method getSharedPreferences(Strin...
android - Initialize preferences from XML in the main Activity
This question already has answers here:
Can we use preferences accress multiple different acvtivities in android?
I save preferences in one activities but not able to get saved preferences in other activity. I can access saved preferences in the same activity but not in other one.
It is not giving me any error but always gibing null values in second activity.
Below is the code:
First Activity:
public static final String PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor ...
variables - How do I get preferences to work in Android?
I've really been struggling through this. New to Java/Android. I'm writing my first app and this is the first thing that has taken me longer than a couple days of searching to figure out. Here's the setup: It's a BAC calculator / drink counter:
A formula is used to calculate the BAC. Here's the forumla:
Bac = ((StandardDrinks / 2) * (G...
android - Is using Shared Preferences for storing user data reliable?
Will the data still be there after the user restarts his / her phone or changes SIM / battery?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android