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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:19:39+00:00 2026-06-17T12:19:39+00:00

I have code to log a person in with a user name password from

  • 0

I have code to log a person in with a user name password from a web server. The code works fine on my other android devices (Vergin mobile, acer tablet) which are android 2.2 and 3.1.
But it crashes on the new Galaxy phones.

when the code executes
OutputStreamWriter wr3 = new OutputStreamWriter(conn3.getOutputStream());

The code causes a exception Networkonmainthread exception and the reason is null.
I was wondering is their a security issue using android 4,1???? Since it works on my other devices which are 3.1 and 2.2?

code

try {
    // Construct data
    Editable ed = mPassWord.getText();
    cGlobals.PassWord=ed.toString();

    ed = mUserName.getText();
    cGlobals.UserName=ed.toString();

    String data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode( cGlobals.UserName, "UTF-8");
    data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(  cGlobals.PassWord, "UTF-8");


    // Send data
    URL url = new URL("http://www.tellafortune.com/mobile/login.php");
    // URL url = new URL("http://www.hhhhtellafortune.com/mobile/login.php");

    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

    wr.write(data);
    wr.flush();

    // Get the response

    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        out += line;
    }

    wr.close();
    rd.close();

    if (!out.contains("ok"))
        return false;    

    // Send data
    URL url2 = new URL("http://www.tellafortune.com/mobile/getaddr.php");
    // URL url = new URL("http://www.hhhhtellafortune.com/mobile/login.php");

    URLConnection conn2 = url2.openConnection();
    conn2.setDoOutput(true);
    OutputStreamWriter wr2 = new OutputStreamWriter(conn2.getOutputStream());

    wr2.write(data);
    wr2.flush();

    // Get the response

    BufferedReader rd2 = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
    String line2;
    out="";
    while ((line2 = rd2.readLine()) != null) {
        out+=line2;
    }

    wr2.close();
    rd2.close();

    cGlobals.strServerAddre=out.replaceAll("\n","");



    ////////////////////////////////////////////////////////////////////
    //////// Get port number if it is the scocial game
    if (ChatOrGame != 1) {
        // String port=new String(":4999/add");
        String port=new String(":4998/add");
        URL url3 = new URL( cGlobals.strServerAddre + port);

        URLConnection conn3 = url3.openConnection();
        conn3.setDoOutput(true);
        // crashes on this line
        OutputStreamWriter wr3 = new OutputStreamWriter(conn3.getOutputStream());

        wr3.write(data);
        wr3.flush();

        // Get the response

        BufferedReader rd3 = new BufferedReader(new InputStreamReader(conn3.getInputStream()));
        String line3;
        out="";
        while ((line3 = rd3.readLine()) != null) {
            out+=line3;
        }

        wr3.close();
        rd3.close();

        cGlobals.strPortNumber=out.replaceAll("PORT:","");
    }
} catch (Exception e) {
    new AlertDialog.Builder(this)
        .setTitle("Internet Error")
        .setMessage( "Cannot talk to server" )
        .setNeutralButton("close",new DialogInterface.OnClickListener();
}
  • 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-17T12:19:40+00:00Added an answer on June 17, 2026 at 12:19 pm

    The code causes a exception Networkonmainthread exception and the reason is null.

    You are performing network I/O on the main thread. While allowed before Android 4.0, it was never a good idea. Please move your network I/O to a background thread, such as one supplied by an AsyncTask.

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

Sidebar

Related Questions

I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I have the following code (attempting to log a user in programatically): List<GrantedAuthority> authorities
I have this code: var Person = { name: , changes: { name to:
I have the following code: Log.e(MainScreen, 1); ListAction listAction = new ListAction(this); Log.e(MainScreen, 2);
I have this code in JS: if($('.log input:checked')) { alert('login checked'); alert('do what you
I have this code: function Keyboard() { this.log = $('#log')[0]; this.pressedKeys = []; this.bindUpKeys
I have this code.. String you = buf.readLine(); Log.d(STRING, ikaw); StringTokenizer st = new
I have this code , and I want to run Log.d every 1000 milis
I have this code inside a iframe: window.addEventListener('message', function(e){ if(e.data == 'test') console.log(e); },
How to print both to Log.e/d/etc. and to System.out/err/etc.? I have some code that

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.