Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:46:02+00:00 2026-06-10T22:46:02+00:00

I have created an android application for off line concept. when internet connected data

  • 0

I have created an android application for off line concept. when internet connected data can be sync through server.

My tablet pc has more than 5.7GB storage space as internal memory. when I sync data from the server, its reporting an error as out of memory.

I think data storage location is changed, its storing some where else. Can anyone resolve this problem? I think some modification to be made in manifest file.

My sync code

public class sync extends Activity implements OnClickListener {
private static String url = "Json URL";
// Button
Button chktosync, logout_menu;
private ProgressDialog pd;
DBAdapter db = new DBAdapter(this);
JSONArray contacts = null;
JSONArray cropdetails = null;
JSONArray biodetails = null;
String land, area, sf, land_id;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sync);
    logout_menu = (Button) findViewById(R.id.logout_menu);
    logout_menu.setOnClickListener(this);
    chktosync = (Button) findViewById(R.id.chktosync);
    chktosync.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
        pd = ProgressDialog.show(sync.this, "Synchronizing", "Synchronizing...");
        new Thread() {
        public void run() {
        try {
            processThread();
            pestanddisease();
            bioparam();
        } catch (Exception e) {
        Log.e("tag", e.getMessage());
        }
        // dismiss the progress dialog
    pd.dismiss();
}
        }.start();
    }
    });
}
private void processThread() {

// Creating JSON Parser instance
JSONParser jParser = new JSONParser();

// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
    // Getting Array of Contacts
    contacts = json.getJSONArray(loginPage.code);
    db.open();
    // looping through All Contacts
for (int i = 0; i < contacts.length(); i++) {

    JSONObject c = contacts.getJSONObject(i);
    // Storing each json item in variable
    String farmerid = c.getString("farmerid");
    String farmername = c.getString("farmername");
    String farmer_fathername = c.getString("farmer_fathername");
    String farmer_mobilenumber = c.getString("farmer_mobilenumber");
    String districtname = c.getString("districtname");
    String blockname = c.getString("blockname");
    String villagename = c.getString("villagename");

    db.insertFarmer(farmerid, farmername,
            farmer_fathername, farmer_mobilenumber,
            districtname, blockname, villagename);
    //land details
    JSONArray Land = c.getJSONArray("land_details");
            for (int l = 0; l < Land.length(); l++) {
        JSONObject s = Land.getJSONObject(l);
        String survey_no = s.getString("survey_no");
        String area  = s.getString("area");
        String land_type = s.getString("land_type");
        String patternref = s.getString("patternref");
        String crop_matrix_id = s.getString("crop_matrix");
        land_id = s.getString("land_id");
        String season1_crop = s.getString("season1_crop");
        String season2_crop = s.getString("season2_crop");
        String season3_crop = s.getString("season3_crop");
        db.insertlanddetails(farmerid, survey_no, area, land_type, patternref, land_id, crop_matrix_id, season1_crop, season2_crop, season3_crop);
}
db.close();
  } 
catch (JSONException e)
 {
   e.printStackTrace();
   }
}


   public void pestanddisease()
     {
         /// Creating JSON Parser instance
         JSONParser jParser = new JSONParser();
        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(pestdisease);
    try    
    {
    // Getting Array of Contacts
    cropdetails = json.getJSONArray("CropDetails");
    db.open();
    for (int i = 0; i < cropdetails.length(); i++) {
    JSONObject s = cropdetails.getJSONObject(i);
    String cropname = s.getString("crop");
    String pest = s.getString("pest_name");
    String disease = s.getString("disease_name");
    db.insertcrop_pest_details(cropname, pest);
    db.insertcrop_disease_details(cropname, disease);
}
    db.close();
 }      catch (JSONException e) {
    e.printStackTrace();
    }
  }
}

JSONParser code

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url) {

    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();

        is = httpEntity.getContent();


    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    BufferedReader reader;
    try {
         reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),1048576);

        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) 
        {
            line=reader.readLine();
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
         Log.e("JSON", json);   

    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;
    }
}

Log Cat

08-28 02:06:59.199: E/dalvikvm-heap(304): Out of memory on a 9513056-byte allocation.

08-28 02:06:59.446: E/AndroidRuntime(304): Uncaught handler: thread Thread-9 exiting due to uncaught exception
08-28 02:06:59.732: E/AndroidRuntime(304): java.lang.OutOfMemoryError
08-28 02:06:59.732: E/AndroidRuntime(304): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
08-28 02:06:59.732: E/AndroidRuntime(304): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:131)
08-28 02:06:59.732: E/AndroidRuntime(304): at java.lang.StringBuilder.append(StringBuilder.java:271)
08-28 02:06:59.732: E/AndroidRuntime(304): at java.io.BufferedReader.readLine(BufferedReader.java:413)
08-28 02:06:59.732: E/AndroidRuntime(304): at com.login.JSONParser.getJSONFromUrl(JSONParser.java:55)
08-28 02:06:59.732: E/AndroidRuntime(304): at com.login.sync.processThread(sync.java:76)
08-28 02:06:59.732: E/AndroidRuntime(304): at com.login.sync.access$1(sync.java:70)
08-28 02:06:59.732: E/AndroidRuntime(304): at com.login.sync$1$1.run(sync.java:57)
08-28 02:07:00.416: I/dalvikvm(304): threadid=7: reacting to signal 3
08-28 02:07:00.416: E/dalvikvm(304): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:46:03+00:00Added an answer on June 10, 2026 at 10:46 pm

    Json parser working fine. No need to change it into file. Reason for the error is JSON was not coming properly.I did some modification on server side. Now its working fine. Before synchronizing data please ensure that JSON is valid or not.Thanks for your support…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an android application for sending messages to a server for interpretation
friends, i want to delete file data that i have created in android application.
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a button in my Android application & I tried to set
I have a problem regarding Android App. I have created an application that download
I have created my android code wherein I fetch all the data from facebook
I have created android application now I want to launch the .Apk of that
In my android application I have created 2 projects. The main project and a
I have created android application integrating with twitter and my application wants to authenticate
I am developing an android application in which i have created five tabs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.