Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:18:42+00:00 2026-05-30T00:18:42+00:00

First – sorry for my english;) I’am writing profile manager for Android and i

  • 0

First – sorry for my english;) I’am writing profile manager for Android and i want getString from a few SharedPreferences file and create listView. It’s part of my code:

private static final String PN = "profile_name";
private EditTextPreference editText;
private SharedPreferences preferences;

public class Profile_Preferences extends PreferenceActivity {

...

private void SavePreferences() {

    String text= editText.getText().toString();
    preferences = getSharedPreferences("Profile_" + text, Activity.MODE_PRIVATE);  //Here we created SharedPreferences file with name "Profile_"+ this what user write in editText

    SharedPreferences.Editor preferencesEditor = preferences.edit();
    preferencesEditor.putString(PN, editText.getText());
    preferencesEditor.commit();

Ok. The user was doing a few profile, so we have file for example: Profile_home.xml, Profile_work.xml, Profile_something.xml. Now i wan’t create listView with profile name from this file. It’s my next Activity:

public class Tab_profiles extends ListActivity {

ArrayList<String> listItems = new ArrayList<String>();  
ArrayAdapter<String> adapter; 

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list);

    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, listItems);
    setListAdapter(adapter);
 ...

public void LoadList() {        

 //It's a good idea to getString "profile_name" form every xml file with name "Profile_" + "" ? 
    preferences = getSharedPreferences("Profile_"+ "", Activity.MODE_PRIVATE);

    String take_profile_name = preferences.getString("profile_name", null);
    listItems.add(take_profile_name );
    adapter.notifyDataSetChanged();

}

But this doesn’t work… logcat log:

FATAL EXCEPTION: MAIN 
java.land.Null.PointerException
at android.widget.ArrayAdaper.createViewFromResource(ArrayAdapter.java:355)
...

I don’t now whoat it’s wrong…

Please help my:) Thank you for any answers and sorry for my errors in writing and code;)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:18:43+00:00Added an answer on May 30, 2026 at 12:18 am

    There are a few problems in your code:

    String text = editText.getText().toString();
    preferences = getSharedPreferences("Profile_" + text, Activity.MODE_PRIVATE);
    
    SharedPreferences.Editor preferencesEditor = preferences.edit();
    preferencesEditor.putString(PN, editText.getText());
    

    If a user types “home” in the EditText, you create a preference file called “Profile_home” and save its name in the same file? You need to save the user generated file names in a different file which has a name you know, so you can access it in your code.

    Second problem:

    preferences = getSharedPreferences("Profile_" + "", Activity.MODE_PRIVATE);
    String take_profile_name = preferences.getString("profile_name", null);
    

    You’re trying to open “Profile_” settings. This file does not exist(?). The second parameter of getString must not be null, otherwise you’ll add a null-reference to your list of string, which fails. Replace it with an empty string “”.

    Edit: Here’s a little workaround to get all custom named preferences:

    private void SavePreferences() {
        String text = editText.getText().toString();
        preferences = getSharedPreferences("ProfileNames", Activity.MODE_PRIVATE);
        SharedPreferences.Editor preferencesEditor = preferences.edit();
        // increment index by 1
        preferencesEditor.putInt("profile_count", preferences.getInt("profile_count", 0) + 1);
        // save new name in ProfileNames.xml with key "name[index]"
        preferencesEditor.putString("name" + (preferences.getInt("profile_count", 0) + 1), editText.getText());
        preferencesEditor.commit();
    }
    
    public void LoadList() {        
        preferences = getSharedPreferences("ProfileNames", Activity.MODE_PRIVATE);
        List<String> profileNames = new LinkedList<String>();
        int profileCount = preferences.getInt("profile_count", 0);
        for (int i = 1; i <= profileCount; i++) {
            profileNames.add(preferences.getString(name + i, ""));
        }
        listItems.addAll(profileNames);
        adapter.notifyDataSetChanged();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first, sorry for my bad English. I try to rewrite url generated from Form
First sorry for my english. I am currently trying to develop a JAVA webservice
first of all sorry for my bad english. I got a working PagerAdapter with
First of all hello people, and sorry for my bad English, I'm Brazillian! I've
first take a look on this picture from localScope app : i have 2
First off, I'm coming (back) to Java from C#, so apologies if my terminology
First i selected images from photo library to ALAsset Library and after that i
first sorry if its a stupid question but im lost a bit. So when
First, xml is as follows: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical >
First I want to thank you guys here, because your posts have gotten me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.