I have an ArrayList
of testobject
And I want to save it in sqlite database.
class testobject {
public static String x="";
public staticint y=0;
public static boolean z=false;
}
after some search I found this example And I use it.
ArrayList<testobject> items=new ArrayList<testobject()>;
items.add(new testobject());
//To insert,
JSONObject json = new JSONObject();
json.put("uniqueArrays", new JSONArray(items));
String arrayList = json.toString();
// Insert the string into db.
//To Read, Read the string from db as String,
JSONObject json = new JSONObject(stringreadfromsqlite);
ArrayList items = json.optJSONArray("uniqueArrays");
Log.d("","itemssize="+items.size);
but the problem is when I want to read my ArrayList
from database, it gives this error message for this line "Log.d("","itemssize="+items.size);":
java.long.NullPointException
actually inested of this line "JSONObject json = new JSONObject(stringreadfromsqlite);" I use "JSONObject json = new JSONObject();" is it myproblem for that?
whats wrong?
as @satur9nine said its dosn't possible to convert my ArrayList to json. so how can i save my arraylist?