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

  • SEARCH
  • Home
  • 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 7806301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:29:26+00:00 2026-06-02T02:29:26+00:00

I wrote app for android and i have one problem. It works on phone,

  • 0

I wrote app for android and i have one problem. It works on phone, but it doesn’t work on tablet.
I have Error : Error in http connection android.os.networkonmainthreadexception. It is my code:

public class AktualizacjaActivity {
public static final String KEY_121 = “http://xxx.php”;

public String getServerData(String returnString,Context context) {
    DatabaseAdapter db1 = new DatabaseAdapter(context);
    db1.open();
    String question="";
    try
    {

        Cursor c = db1.makeCursor(DatabaseAdapter.STRUCT, new String[] {DatabaseAdapter.ID},DatabaseAdapter.KODE_ID+"='"+returnString+"'",null);
        c.moveToFirst();
        question+="NOT IN('";
        while(!c.isLast())
        {
        question+=c.getString(c.getColumnIndex(DatabaseAdapter.ID))+"','";
        c.moveToNext();
        }
        question+=c.getString(c.getColumnIndex(DatabaseAdapter.ID))+"')";

    }
    catch(Exception e)
    {

    }

    db1.close();
    if(question.equalsIgnoreCase("NOT IN('")) question="";


   InputStream is = null;

   String result = "";
    //the year data to send, warunek rok większy od 1980
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("code_id",returnString));
    nameValuePairs.add(new BasicNameValuePair("no", question));

    //http post
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(KEY_121);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();


    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }

    //convert response to string
    try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"ISO-8859-2"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();

    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }
    //parse json data
    DatabaseAdapter db = new DatabaseAdapter(context);
    db.open();
    try{


            JSONArray jArray = new JSONArray(result);

            for(int i=0;i<jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);

                  db.addItmem("INSERT INTO my_kodeks_struktura VALUES("  
                    +json_data.getInt("id")+","
                    +json_data.getInt("code_id")+","+
                    json_data.getInt("position_art")+",'"+
                    json_data.getString("position_art_a")+"',"+
                    json_data.getInt("level")+",'"+
                    json_data.getString("name")+"');");



            }


    }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }
    db.close();
    return "Upd"; 

}    



}
  • 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-02T02:29:27+00:00Added an answer on June 2, 2026 at 2:29 am

    it’s as the exception says: you cannot make http calls on ui thread. at least not on newer OS.

    consider using AsyncTask for such calls.

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

Sidebar

Related Questions

I wrote an android app for someone, but they want the source code because
I have developed an android app that mainly targets smartphones. However in tablet emulator
I am developing one android app in that i have to post some message
In my current app for Android I have an HTTP client that sends a
I have an Android app that communicates with a server via asynchronous socket connection
I wrote an android app and so far it works perfect except for on
Hey there, i have one question.. i try to write an android app with
In my Android app, I have a Bitmap object and an int[]. One algorithm
I wrote an Android App using the Mixare ( link to mixare project )
I am trying to learn Android app development and wrote a very simple app

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.