I’m trying to load Content Values into a database. The code here works:
private void processTable(final JsonReader tableReader, final ModelLoader loader) throws IOException
{
tableReader.beginArray();
while (tableReader.hasNext()) {
String id = loader.getIdColumnName();
final ContentValues cv = loader.parseModel(tableReader);
persistData(loader.getTableName(),id, cv);
}
tableReader.endArray();
}
However, when I add an additional part into it, it fails.
private void processTable(final JsonReader tableReader, final ModelLoader loader) throws IOException
{
tableReader.beginArray();
while (tableReader.hasNext()) {
String id = loader.getIdColumnName();
final ContentValues cv = loader.parseModel(tableReader);
if (loader.getModelType() == Filter.LOADER.getModelType()) //Checks to see if the filter sub arrays are there
{
while(tableReader.hasNext())
{
String name = "";
try{
tableReader.
name = tableReader.nextName();
} catch (Exception e) {
tableReader.skipValue();
continue;
}
if (name.equals("ImageOverlays"))
processTable(tableReader, mLoader.getSpecificLoader("ImageOverlays"));
else if (name.equals("ColorOverlays"))
processTable(tableReader, mLoader.getSpecificLoader("ColorOverlays"));
}
}
persistData(loader.getTableName(),id, cv);
}
tableReader.endArray();
}
The purpose of the additional code is to get a particular item from the Filters and then process them. When I use this code, I don’t even get any values for the Filters which I used to before.
I think that me skipping the values is somehow screwing up the ContentValues cv that I declare before it.
Thanks for any help.
So Its your Interior loop causing the problem which is skipping the JSON Objects that have to be parsed…
And Yeah the Content Values as you mentioned in the comments are not valid by the time you reach the end of the loop.