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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:45:06+00:00 2026-06-18T22:45:06+00:00

My issue is pretty same that this one, but I’m not creating any output

  • 0

My issue is pretty same that this one, but I’m not creating any output streams yet

FATAL Exception Main android

    // Try to connect

    try {

        // Check the network state
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

        // If there is conection, try to create a socket with remote server
        if (networkInfo.isConnected()) {
            InetAddress address = InetAddress
                    .getByName(serverAdressTextField.getText().toString());
            Socket serverConnection = new Socket(address, PORT);


            // Write message of success
            //TODO Implement the rest of login function
            Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
        } else {

            // Say user that there is no internet

            Toast.makeText(this, "No connection", Toast.LENGTH_SHORT)
                    .show();
        }



    // Catch unknown host and prompt error
    } catch (UnknownHostException e) {

        Toast.makeText(this, "Server is not reached", Toast.LENGTH_SHORT)
                .show();
        return;

    // Prompt IO exception
    } catch (IOException e) {

        Toast.makeText(this, "I/O Error", Toast.LENGTH_SHORT).show();
        return;


    // Any other exception, not good
    } catch (Exception e) {

        Toast.makeText(this, "Unknown Error", Toast.LENGTH_SHORT).show();
        return;

    }

It throws IllegalStateException and If not catched it gives that

    02-17 05:29:59.655: E/AndroidRuntime(18470): FATAL EXCEPTION: main
    02-17 05:29:59.655: E/AndroidRuntime(18470): java.lang.IllegalStateException: Could not         execute method of the activity
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.view.View$1.onClick(View.java:3591)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.view.View.performClick(View.java:4084)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.view.View$PerformClick.run(View.java:16966)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.os.Handler.handleCallback(Handler.java:615)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.os.Handler.dispatchMessage(Handler.java:92)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.os.Looper.loop(Looper.java:137)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.lang.reflect.Method.invoke(Method.java:511)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at dalvik.system.NativeStart.main(Native Method)
    02-17 05:29:59.655: E/AndroidRuntime(18470): Caused by: java.lang.reflect.InvocationTargetException
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.lang.reflect.Method.invoke(Method.java:511)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.view.View$1.onClick(View.java:3586)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    ... 11 more
    02-17 05:29:59.655: E/AndroidRuntime(18470): Caused by: android.os.NetworkOnMainThreadException
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at libcore.io.IoBridge.connect(IoBridge.java:112)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.net.Socket.startupSocket(Socket.java:566)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at java.net.Socket.<init>(Socket.java:225)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    at com.snivik.morze.LoginWindow.connectToServer(LoginWindow.java:62)
    02-17 05:29:59.655: E/AndroidRuntime(18470):    ... 14 more
  • 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-18T22:45:07+00:00Added an answer on June 18, 2026 at 10:45 pm

    Your problem is that you are obviously trying to open a socket in the main thread, that’s why you are getting android.os.NetworkOnMainThreadException.

    All networking has to be done in a background thread.

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

Sidebar

Related Questions

This is a pretty esoteric issue that I can't produce a small test case
I don't think I'm the first one to run into this issue but I
This is a pretty minor issue but it's bugging me - I am trying
I encounter this issue pretty consistently when trying to merge a branch back into
I have been researching this issue pretty extensively and cannot seem to find an
I have a pretty common layout issue that I have traditionally used a table
I'm pretty sure I'm having a CSS issue, but I just can't figure out
I'm pretty new in iphone programming and have stumbled upon this issue which I
I'm pretty new to Visual Studio so this might be an easy issue :)
my issue is a bit similar to this one: Having an issue with my

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.