Buggy code:
public class UpdateDatabase extends AsyncTask < String , Integer , String > { private final int CONNECTION_TIMEOUT = 6000 ; private final int SOCKET_TIMEOUT = 6000 ; private Context context ; public UpdateDatabase ( Context context ) { } @ Override protected String doInBackground ( String ... params ) { } protected void onProgressUpdate ( Integer ... progress ) { } protected void onPostExecute ( String result ) { } private HttpClient createHttpClient ( ) { } private String Post ( String url , List < BasicNameValuePair > nameValuePairs ) { } public String load ( String url ) { List < BasicNameValuePair > nameValuePairs = new ArrayList < BasicNameValuePair > ( ) ; final SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ; String timestamp = prefs . getString ( "lastOpened" , "1330910642" ) ; nameValuePairs . add ( new BasicNameValuePair ( "timestamp" , timestamp ) ) ; String result = Post ( url , nameValuePairs ) ; JsonStreamParser parser = new JsonStreamParser ( result ) ; SQLiteDatabase db = new Database ( context ) . getWritableDatabase ( ) ; <START_BUG> if ( ! ( result . equals ( "null" ) ) ) { <END_BUG> JsonArray arr = parser . next ( ) . getAsJsonArray ( ) ; for ( int i = 0 ; i < ( arr . size ( ) ) ; i ++ ) { if ( arr . get ( i ) . isJsonObject ( ) ) { JsonObject ob = arr . get ( i ) . getAsJsonObject ( ) ; int rid = ob . get ( "rid" ) . getAsInt ( ) ; String name = ob . get ( "name" ) . getAsString ( ) ; String address = ob . get ( "address" ) . getAsString ( ) ; String city = ob . get ( "city" ) . getAsString ( ) ; String state = ob . get ( "state" ) . getAsString ( ) ; String country = ob . get ( "country" ) . getAsString ( ) ; int lat = ob . get ( "lat" ) . getAsInt ( ) ; int lon = ob . get ( "lon" ) . getAsInt ( ) ; db . execSQL ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "INSERT<seq2seq4repair_space>OR<seq2seq4repair_space>REPLACE<seq2seq4repair_space>INTO<seq2seq4repair_space>restaurants<seq2seq4repair_space>(rid,<seq2seq4repair_space>name,<seq2seq4repair_space>address,<seq2seq4repair_space>city,<seq2seq4repair_space>state,<seq2seq4repair_space>country,<seq2seq4repair_space>lat,<seq2seq4repair_space>lon)<seq2seq4repair_space>VALUES<seq2seq4repair_space>(" + rid ) + ",<seq2seq4repair_space>'" ) + name ) + "',<seq2seq4repair_space>'" ) + address ) + "',<seq2seq4repair_space>'" ) + city ) + "',<seq2seq4repair_space>'" ) + state ) + "',<seq2seq4repair_space>'" ) + country ) + "',<seq2seq4repair_space>" ) + lat ) + ",<seq2seq4repair_space>" ) + lon ) + ")" ) ) ; } } arr = parser . next ( ) . getAsJsonArray ( ) ; for ( int i = 0 ; i < ( arr . size ( ) ) ; i ++ ) { if ( arr . get ( i ) . isJsonObject ( ) ) { JsonObject ob = arr . get ( i ) . getAsJsonObject ( ) ; int iid = ob . get ( "iid" ) . getAsInt ( ) ; String name = ob . get ( "name" ) . getAsString ( ) ; String description = ob . get ( "description" ) . getAsString ( ) ; String price = ob . get ( "price" ) . getAsString ( ) ; int veg = ob . get ( "veg" ) . getAsInt ( ) ; db . execSQL ( ( ( ( ( ( ( ( ( ( ( "INSERT<seq2seq4repair_space>OR<seq2seq4repair_space>REPLACE<seq2seq4repair_space>INTO<seq2seq4repair_space>items<seq2seq4repair_space>(iid,<seq2seq4repair_space>name,<seq2seq4repair_space>description,<seq2seq4repair_space>price,<seq2seq4repair_space>veg)<seq2seq4repair_space>VALUES<seq2seq4repair_space>(" + iid ) + ",<seq2seq4repair_space>'" ) + name ) + "',<seq2seq4repair_space>'" ) + description ) + "',<seq2seq4repair_space>'" ) + price ) + "',<seq2seq4repair_space>" ) + veg ) + ")" ) ) ; } } arr = parser . next ( ) . getAsJsonArray ( ) ; for ( int i = 0 ; i < ( arr . size ( ) ) ; i ++ ) { if ( arr . get ( i ) . isJsonObject ( ) ) { JsonObject ob = arr . get ( i ) . getAsJsonObject ( ) ; int rid = ob . get ( "rid" ) . getAsInt ( ) ; int iid = ob . get ( "iid" ) . getAsInt ( ) ; db . execSQL ( ( ( ( ( "INSERT<seq2seq4repair_space>OR<seq2seq4repair_space>REPLACE<seq2seq4repair_space>INTO<seq2seq4repair_space>restaurants_items<seq2seq4repair_space>(rid,<seq2seq4repair_space>iid)<seq2seq4repair_space>VALUES<seq2seq4repair_space>(" + rid ) + ",<seq2seq4repair_space>" ) + iid ) + ")" ) ) ; } } } SharedPreferences . Editor editor = prefs . edit ( ) ; editor . putString ( "lastOpened" , ( ( ( System . currentTimeMillis ( ) ) // 1000 ) + "" ) ) ; editor . commit ( ) ; db . close ( ) ; return "" ; } No newline ; at end ; of file ; }

Fix:
if ( parser . hasNext ( ) ) {