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 8180341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:11:35+00:00 2026-06-07T00:11:35+00:00

I am having issues with networking being very slow.. For testing purposes, I tried

  • 0

I am having issues with networking being very slow.. For testing purposes, I tried to cut out asynctask completely with Android 4.0.4 and of course I need to avoid my network calls on the main thread or I get the networkNotOnMainThread exception.. So I wrapped my call in a thread and I am STILL getting this error. What the heck is wrong here??

public class DrupalTestActivity extends Activity {

    private Context mCtx;

    final static String URL = "http://www.mytestsite.com/";
    final static String ENDPOINT = "rest/";
    String mResponse = null;
    TextView textView;




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textView = (TextView) findViewById(R.id.textView);
                //retrieves the user account JSON object.
        JSONObject mUserAccount = UserAccount.getJSONUserAccount(this);
                //login using the JSON
        userLogin(mUserAccount);
    }



    public void userLogin(final JSONObject mUserAccount) {
        Thread t = new Thread() {
            public void run() {
                String uri = URL + ENDPOINT + "user/login";
                HttpPost httppost = new HttpPost(uri);
                httppost.setHeader("Content-type", "application/json");
                StringEntity se;
                try {
                    HttpClient mHttpClient = new DefaultHttpClient();
                    HttpParams mHttpParams = new BasicHttpParams();
                    HttpConnectionParams.setConnectionTimeout(mHttpParams,
                            10000);
                    HttpConnectionParams.setSoTimeout(mHttpParams, 10000);

                    se = new StringEntity(mUserAccount.toString());
                    se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                            "application/json"));
                    httppost.setEntity(se);
                    Log.d("STATUS", "CALLING DRUPAL");
                    ResponseHandler<String> handler = new BasicResponseHandler();
                    mResponse = mHttpClient.execute(httppost, handler);
                    mHttpClient.getConnectionManager().shutdown();


                    Log.d("STATUS", "LOGIN COMPLETE");
                    Log.d("RESPONSE", mResponse);

                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };
        t.run();
    }
}

User Account method.. I don’t think it’s even part of the problem.

public static JSONObject getJSONUserAccount(Context ctx) {
        SharedPreferences accountSettings = PreferenceManager
                .getDefaultSharedPreferences(ctx);
        String nUsername = accountSettings.getString("username", "tester");
        String nPassword = accountSettings.getString("password", "password");
        JSONObject JSONUser = new JSONObject();
        try {
            JSONUser.put("password", nPassword);
            JSONUser.put("username", nUsername);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return JSONUser;
    }

Log is..

07-05 10:34:58.377: E/AndroidRuntime(32538): FATAL EXCEPTION: main
07-05 10:34:58.377: E/AndroidRuntime(32538): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.seine.drupal/com.seine.drupal.DrupalTestActivity}: android.os.NetworkOnMainThreadException
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2049)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2083)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.os.Looper.loop(Looper.java:137)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread.main(ActivityThread.java:4697)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at java.lang.reflect.Method.invokeNative(Native Method)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at java.lang.reflect.Method.invoke(Method.java:511)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at dalvik.system.NativeStart.main(Native Method)
07-05 10:34:58.377: E/AndroidRuntime(32538): Caused by: android.os.NetworkOnMainThreadException
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1119)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at java.net.InetAddress.lookupHostByName(InetAddress.java:441)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:243)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at java.net.InetAddress.getAllByName(InetAddress.java:220)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at com.seine.drupal.DrupalTestActivity.userLogin(DrupalTestActivity.java:90)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at com.seine.drupal.DrupalTestActivity$1.run(DrupalTestActivity.java:65)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at com.seine.drupal.DrupalTestActivity.onCreate(DrupalTestActivity.java:69)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.Activity.performCreate(Activity.java:4539)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-05 10:34:58.377: E/AndroidRuntime(32538):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2013)
07-05 10:34:58.377: E/AndroidRuntime(32538):    ... 11 more

I am baffled and this must be something new in ICS because this all worked in earlier versions of android. Am I really forced to used AsyncTask? I just can’t believe that.

  • 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-07T00:11:36+00:00Added an answer on June 7, 2026 at 12:11 am

    You’re calling run() on the thread object instead of start(). Calling run() just executes your thread procedure on the main thread.

    The line goes

    t.run(); 
    

    in the very end. Should be

    t.start(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having issues testing out the Scala Parser Combinator functionality for a simple
having some issues with a networking assignment. End goal is to have a C
I am having issues testing which icon my notifyIcon is using. I have a
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Still having issues with this problem. Please help if you can. So I am
Im having issues getting this to work, maybe its not even possible? I have
Im having issues vertically positioning text inside of a text input field in Firefox.
I am having issues with trying to convert an UTF-8 string to unicode. I
I'm having issues with a bit of code that I am writing in C#.
I am having issues getting the -e and -d file test operators to work

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.