I'm trying to load a lot of data from the web to my android application and I've been getting this error:
07-18 10:16:00.575: E/AndroidRuntime(30117): java.lang.OutOfMemoryError: [memory exhausted]
and already read a lot about JSON. I've found some solutions but nothing really helped me.
This is my code :
public class HistoricoAdapter extends BaseAdapter {
    private Context ctx;
    JSONArray jsonArray;
    public HistoricoAdapter(Context ctx) {
        this.ctx = ctx;
        String readHttp = readHttp();
        try {
            // transforma a string retornada pela função readHttp() em array
            jsonArray = new JSONArray(readHttp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String readHttp() {
        // Acessa a URL que retorna uma string com  os dados do banco
        StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("some url");
        try {
            HttpResponse response = client.execute(httpGet);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (statusCode == 200) {
                HttpEntity entity = response.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
            } else {
                Log.e(this.toString(), "Erro ao ler JSON!");
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return builder.toString();
    }
    public int getCount() {
        return jsonArray.length();
    }
    public boolean isEmpty(){
        if(jsonArray.toString().isEmpty()){
            return true;
        }
        else {
            return false;
        }
    }
    public Object getItem(int position) {
        JSONObject ob = null;
        try {
            ob = jsonArray.getJSONObject(position);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return ob;
    }
    public long getItemId(int arg0) {
        return 0;
    }
    public View getView(int position, View view, ViewGroup arg2) {
        LayoutInflater layout = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = layout.inflate(R.layout.listar_compromisso, null);
        try {
            JSONObject obj = (JSONObject) getItem(position);
        } catch (Exception ex) {
        }
        return v;
    }
}
Can anyone predict why am I getting this error?
 
     
     
    