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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:05:16+00:00 2026-06-05T07:05:16+00:00

I have the following weird problem. My main activity looks like this: public class

  • 0

I have the following weird problem.

My main activity looks like this:

public class CityGame extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent myIntent = new Intent(this, XMPPClient.class);
    startActivity(myIntent);

 }
}

I striped the code down to find the problem. The code above does nothing more then jumping directly to the XMPPClient activity. XMPPClient activity is using the asmack.jar library and that library is added to my eclipse build path.

The XMPPClient activity code:

public class XMPPClient extends Activity {

/**
 * Called with the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.i("XMPPClient", "onCreate called");

    //Create a connection to the jabber.org server.
    Connection conn1 = new XMPPConnection("jabber.org");
    try {
        conn1.connect();
    } catch (XMPPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}
}

The problem occurs when I call functions from the asmack.jar lib. For instance the conn1.connect(); crashed my application over and over again. I get errors like:

06-07 09:05:03.085: E/AndroidRuntime(538): FATAL EXCEPTION: main
06-07 09:05:03.085: E/AndroidRuntime(538): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.joop.citygame/com.joop.citygame.XMPPClient}: android.os.NetworkOnMainThreadException
06-07 09:05:03.085: E/AndroidRuntime(538):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-07 09:05:03.085: E/AndroidRuntime(538):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-07 09:05:03.085: E/AndroidRuntime(538):  at android.app.ActivityThread.access$600(ActivityThread.java:122)

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joop.citygame"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk android:minSdkVersion="14" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name" 
        android:name=".CityGame" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:label="@string/app_name"
        android:name=".XMPPClient" >
        <intent-filter>
            <action android:name="com.joop.citygame.XMPPClient" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>

Anyone have an idea on what I’m doing wrong?

INFO: API level 14

  • 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-05T07:05:16+00:00Added an answer on June 5, 2026 at 7:05 am

    Establishing a remote connection can take a long time.
    You are trying to establish a connection directly from an activity and by default this activity is bound to the UI thread.

    As a result, as long as your activity is trying to establish the connection, the user interface is blocked. The user cannot press any button and the screen is frozen.

    By throwing a NetworkOnMainThreadException the android operating system is forcing you to change your implementation and is forcing you to establish your connection from another thread.

    To summarise, you should not try to establish your remote connection from the UI thread. Try to establish it from a IntentService or a Service.
    If you really want to establish it from an activity try to use an AsyncTask or a HandlerThread.

    EDIT : Take a look at the android StrictMode :

    StrictMode is most commonly used to catch accidental disk or network
    access on the application’s main thread, where UI operations are
    received and animations take place.

    It might be enabled for your application.

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

Sidebar

Related Questions

Good day, I have this weird problem: This following statement works Query q =
This is very weird. I have the following code: Assert.AreEqual(new DateTime(2000, 1, 1), DateTime.ParseExact(2000,
I have this weird problem where my Google Maps API script doesn't work, no
I have a weird problem with twig in Symfony2. I am using the following
I have run into a rather weird problem. I have created the following query
i have a weird problem, i've been following a youtube tutrial from Matt Blagden
I have a rather weird problem. I live in denmark and here the first
I have this weird problem.. I'm building an in-house app that should register all
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
I have the following, very weird problem with my WPF app in production environment:

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.