0

I have an ArrayList of RowItem where RowItem Class have following variables :

public class RowItem
{
   private Bitmap photo;
   private String photoURL ;
   private int online_status;
   private String name;
   private String last_seen;
   private int delete;
   //Getters and Setters ...
}

I want to save this ArrayList into internal storage. Here is the list of things I have already tried but aren't working :

  1. Implemented exclusion strategy as indicated in here. Excluded Bitmap from saving as I am Lazy Loading Images From URLs to ListView. But I am still getting errors like :

     java.lang.RuntimeException: Unable to pause activity {com.awesome.clique/com.awesome.clique.Home}: java.lang.IllegalArgumentException: class android.text.BoringLayout declares multiple JSON fields named mPaint.
    

    If I am saving in onPause() or onStop() using SharedPreferences(using gson) or Files.

  2. Overridden methods of readObject and writeObject for RowIem class. But it still kept on giving the above error.

Now I am out of options now. I do now think that saving the ArrayList in SQLite database maybe feasible, but I do not know how to save this list into SQLite databse as I have no idea about SQLite and in a glance it seemed very complex. Please help me out.

1 Answer 1

1

I would suggest you to look at ORMLite, it will simplify how you work with SQLite.

Take a look at how I implemented a simple model here: https://github.com/slidese/BabyFeed/blob/master/src/se/slide/babyfeed/model/FeedLog.java

And have a look (at that same project) how you work with it, it pretty simple.

Your code would look something like this:

@DatabaseTable
public class RowItem
{
   @DatabaseField(generatedId = true)
   private int id;

   @DatabaseField
   private Bitmap photo;

   @DatabaseField
   private String photoURL;

   @DatabaseField
   private int online_status;

   @DatabaseField
   private String name;

   @DatabaseField
   private String last_seen;

   @DatabaseField
   private int delete;

   //Getters and Setters ...
}

And then:

DatabaseManager.getInstance().addRowItem(row);

You create these helper methods, for example a delete could look like this:

public void deleteRowItem(RowItem row) {
    try {
        getHelper().getRowDao().delete(row);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Sign up to request clarification or add additional context in comments.

10 Comments

Can you tell me , how will I delete a particular row ?
It's a bit too much code to paste here. But you could look at how I'm working with it in the DatabaseManager and DatabaseHelper classes here: github.com/slidese/BabyFeed/blob/master/src/se/slide/babyfeed/…
In your code there is a function for adding FeedLogs, its okay but I am a little puzzled that how will I delete a particular FeedLog or RowItem ? If you could just paste the function for delete only, that would be very helpful.
@SlashGeek I added a delete helper method to the answer.
Hey I am getting a NullPointerException along with the following warnings : ": unable to find class referenced in signature (Lcom/j256/ormlite/dao/Dao;) VFY: unable to resolve interface method: Lcom/j256/ormlite/dao/Dao;.create (Ljava/lang/Object;)I". What is happening ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.