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 8114317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:06:48+00:00 2026-06-06T03:06:48+00:00

In my app, I’m using getPreferences(MODE_PRIVATE) with putString() , putBoolean() , etc. to save

  • 0

In my app, I’m using getPreferences(MODE_PRIVATE) with putString(), putBoolean(), etc. to save app state. The amount of data is not great – possible a few strings and a couple of boolean values. I never get any errors when saving the data, however when I read it, sometimes I get XML errors. For example, I’m trying to read the the values with this code:

String cr = getPreferences(MODE_PRIVATE).getString("user-input-" + block.getID(), "");

Sometimes this works just fine and on other occasions it produces this error:

03-22 12:42:25.846: W/ApplicationContext(406): getSharedPreferences
03-22 12:42:25.846: W/ApplicationContext(406): org.xmlpull.v1.XmlPullParserException: Error parsing document. (position:line -1, column -1) caused by: org.apache.harmony.xml.ExpatParser$ParseException: At line 3, column 29: not well-formed (invalid token)
03-22 12:42:25.846: W/ApplicationContext(406):  at org.apache.harmony.xml.ExpatPullParser$ByteDocument.flush(ExpatPullParser.java:959)
03-22 12:42:25.846: W/ApplicationContext(406):  at org.apache.harmony.xml.ExpatPullParser$Document.pump(ExpatPullParser.java:770)
03-22 12:42:25.846: W/ApplicationContext(406):  at org.apache.harmony.xml.ExpatPullParser$Document.dequeue(ExpatPullParser.java:814)
03-22 12:42:25.846: W/ApplicationContext(406):  at org.apache.harmony.xml.ExpatPullParser.next(ExpatPullParser.java:303)
03-22 12:42:25.846: W/ApplicationContext(406):  at com.android.internal.util.XmlUtils.readValueXml(XmlUtils.java:674)
03-22 12:42:25.846: W/ApplicationContext(406):  at com.android.internal.util.XmlUtils.readMapXml(XmlUtils.java:469)
03-22 12:42:25.846: W/ApplicationContext(406):  at android.app.ApplicationContext.getSharedPreferences(ApplicationContext.java:340)
03-22 12:42:25.846: W/ApplicationContext(406):  at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
03-22 12:42:25.846: W/ApplicationContext(406):  at android.app.Activity.getPreferences(Activity.java:3444)
03-22 12:42:25.846: W/ApplicationContext(406):  at com.mypackage.BlockActivity$SetupTask.doInBackground(BlockActivity.java:79)
03-22 12:42:25.846: W/ApplicationContext(406):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-22 12:42:25.846: W/ApplicationContext(406):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-22 12:42:25.846: W/ApplicationContext(406):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-22 12:42:25.846: W/ApplicationContext(406):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-22 12:42:25.846: W/ApplicationContext(406):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-22 12:42:25.846: W/ApplicationContext(406):  at java.lang.Thread.run(Thread.java:1096)

Line 79 in my code is the one shown above. Any ideas on what’s going on and how to fix this? Many thanks.

  • 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-06-06T03:06:49+00:00Added an answer on June 6, 2026 at 3:06 am

    After struggling with this for a while, getting this error on both emulator (different versions) and two different handsets, I backed away from saving data into shared preferences. I still keep the boolean and integer values in shared prefs, but save string data into a file. This works every time and never game me any problems.

    One thing of note is that some of the strings may be very long, possibly a few thousand chars. Maybe it had something to do with the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app has several buttons which trigger different events. The user should NOT be
My app is crashing using iOS5 and iOS4.3 iPhone simulators in Xcode 4.2, the
App runs on simulator on my MacBook Air, but not on iMac. I have
My app runs fine in the ios 4.3 simulator, but not the ios 5
My app is slowed down by N+1 queries. I'm using the will_paginate gem with
We're building an app, our first using Rails 3, and we're having to build
My app must NOT auto -rotate at all. But it includes a screen which
My app has a datagrid as well as many other UIComponents (buttons, menus, etc).
My app keeps track of the state of about 1000 objects. Those objects are
Our app (already deployed) is using an Access/Jet database. The upcoming version of our

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.