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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:49:07+00:00 2026-06-04T00:49:07+00:00

I have a problem when I use GSON. First off I’m trying to save

  • 0

I have a problem when I use GSON.

First off I’m trying to save an Object inside SharedPreferences with the use of GSON, whenever I switch activities. Then my plan was to get that object again once I get back to the activity so that I can repopulate the captured data on that page. But, my problem is that an error occurs on my onPause method. This error has already been bugging me for 2 days, I hope you guys can help. I seriously need it.

Here is my onPause and onResume code:

    @Override
protected void onPause() {
    super.onPause();

    try {
        SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
        Editor prefsEditor = appSharedPrefs.edit();

        activityDataContainer = convertDataContainers(); //This just gets the data from the page

        prefsEditor.putInt("objectLength", activityDataContainer.size());
        Gson gson = new Gson();
        for(int x = 0; x < activityDataContainer.size(); x++){
            ConnectionObject temp = activityDataContainer.get(x);
            String json = gson.toJson(temp);
            prefsEditor.putString("connectionData"+x, json);
        }

        prefsEditor.commit();
        Toast.makeText(this, "Object stored in SharedPreferences", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

};

@Override
protected void onResume() {
    super.onResume();

    //===== Using SharedPreferences
    SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
    if(appSharedPrefs.contains("objectLength")){

        int length = appSharedPrefs.getInt("objectLength", 0);
        activityDataContainer = new ArrayList<ConnectionObject>();
        Gson gson = new Gson();
        for(int x = 0; x < length; x++){
            String json = appSharedPrefs.getString("connectionData"+x, "");
            ConnectionObject object = gson.fromJson(json, ConnectionObject.class);
            activityDataContainer.add(object);
        }

        revertDataContainers(activityDataContainer); //Repopulates the data
        Toast.makeText(this, "Object retrieved in SharedPreferences", Toast.LENGTH_SHORT).show();
    }
}

Here is the Error Log I get:

05-10 02:14:47.822: E/AndroidRuntime(31718): FATAL EXCEPTION: main
05-10 02:14:47.822: E/AndroidRuntime(31718): java.lang.RuntimeException: Unable to pause activity {com.NelConsulting.FieldCaptureTool/com.MyClass}: java.lang.IllegalArgumentException: class android.database.sqlite.SQLiteDatabase declares multiple JSON fields named mLock
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.access$1700(ActivityThread.java:117)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.os.Looper.loop(Looper.java:130)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.main(ActivityThread.java:3683)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at java.lang.reflect.Method.invokeNative(Native Method)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at java.lang.reflect.Method.invoke(Method.java:507)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at dalvik.system.NativeStart.main(Native Method)
05-10 02:14:47.822: E/AndroidRuntime(31718): Caused by: java.lang.IllegalArgumentException: class android.database.sqlite.SQLiteDatabase declares multiple JSON fields named mLock
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.getAdapter(Gson.java:349)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:82)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.getAdapter(Gson.java:349)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.getAdapter(Gson.java:349)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:82)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.getAdapter(Gson.java:349)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:55)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.toJson(Gson.java:582)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.toJson(Gson.java:561)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.toJson(Gson.java:516)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.google.gson.Gson.toJson(Gson.java:496)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at com.MyClass.onPause(ConnectionsActivity.java:804)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.Activity.performPause(Activity.java:3851)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191)
05-10 02:14:47.822: E/AndroidRuntime(31718):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2341)

All help will be greatly appreciated. Much thanks in advance.

**EDIT
**ConnectionObject is a simple object that stores these values:

private boolean toggleButtonValue;
private int sdGenValue;
private int sdSpecValue;
private int sdCountValue;
private String sdLengthValue;
private int sdCondValue;
private int sdOwnValue;
private String sdDateValue;
private String mLtValue;
private String mLgValue;
private String mAcValue;
private int mPhotoValue;
private List<MeterObject> meterContainer;
  • 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-04T00:49:09+00:00Added an answer on June 4, 2026 at 12:49 am

    I solved it, though I think its just a loop around idea. I just split my object into 2 parts. The first being the String and int values, and the second one being the list. I stored both parts separately then combine them again on resume. Thanks for the ideas guys. It was a lot of help.

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

Sidebar

Related Questions

Ok I have this problem I'm trying to use Jquery to load a partial
I have never done much with serialization, but am trying to use Google's gson
I have problem with types in my schema when trying to use xsd:any element
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
I'm new in codeigniter I have problem I use my OS X Lion, and
I have problem with setting proper charset on my jsf pages. I use MySql
In a couple of scripts that I use I have problem that is intermittent.
I have quite a problem concerning the use of relational database concepts in Delphi
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I become use raw socket and i have this problem: bad file descriptor the

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.