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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:09:56+00:00 2026-06-16T15:09:56+00:00

after trying my brand new service on android i get this: i guess is

  • 0

after trying my brand new service on android i get this:

i guess is something related to the manifest file and permissions, the service is started after the last activity, to update data on server and retrieve new data and save id on sqlite on android:

here also the manifest file:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.ggservice.democracy"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.INTERNET"/>

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.ggservice.democracy.MainActivity"
                android:label="@string/app_name" >
                <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="com.ggservice.democracy.sondaggioActivity"/>
            <activity android:label="@string/app_name" android:name="com.ggservice.democracy.domandeDiCategoria"/>
            <service android:name="com.ggservice.democracy.updateDemocracyService" />
        </application>

    </manifest>

the logcat:

01-02 15:33:30.960: W/dalvikvm(2570): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-02 15:33:31.160: E/AndroidRuntime(2570): FATAL EXCEPTION: main
01-02 15:33:31.160: E/AndroidRuntime(2570): java.lang.RuntimeException: Unable to start service com.ggservice.democracy.updateDemocracyService@412f0c60 with Intent { cmp=com.ggservice.democracy/.updateDemocracyService }: android.os.NetworkOnMainThreadException
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2376)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.app.ActivityThread.access$1900(ActivityThread.java:123)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.os.Looper.loop(Looper.java:137)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at java.lang.reflect.Method.invokeNative(Native Method)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at java.lang.reflect.Method.invoke(Method.java:511)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at dalvik.system.NativeStart.main(Native Method)
01-02 15:33:31.160: E/AndroidRuntime(2570): Caused by: android.os.NetworkOnMainThreadException
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at com.ggservice.democracy.JSONParser.getJSONFromUrl(JSONParser.java:38)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at com.ggservice.democracy.updateDemocracyService.onStartCommand(updateDemocracyService.java:47)
01-02 15:33:31.160: E/AndroidRuntime(2570):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
01-02 15:33:31.160: E/AndroidRuntime(2570):     ... 10 more

am i doing something wrong?

this is also the service:

public class updateDemocracyService extends Service{
    private pollDataSource datasource;
     int mStartMode;       // indicates how to behave if the service is killed
        IBinder mBinder;      // interface for clients that bind
        boolean mAllowRebind; // indicates whether onRebind should be used
        // url to make request
        private static String url = "http://www.test.com/democracy/domande.php";

        // JSON Node names
        private static final String TAG_DOMANDE = "domande";
        private static final String TAG_ID = "id";
        private static final String TAG_TESTO = "testo";


        // contacts JSONArray
        JSONArray contacts = null;

        @Override
        public void onCreate() {
            // The service is being created
            datasource = new pollDataSource(this);
            datasource.open();

        }
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {

            // Creating JSON Parser instance
            JSONParser jParser = new JSONParser();

            // getting JSON string from URL
            JSONObject json = jParser.getJSONFromUrl(url);

            try {
                // Getting Array of Contacts
                contacts = json.getJSONArray(TAG_DOMANDE);

                // looping through All Contacts
                for(int i = 0; i < contacts.length(); i++){
                    JSONObject c = contacts.getJSONObject(i);

                    // Storing each json item in variable
                    String id = c.getString(TAG_ID);
                    String name = c.getString(TAG_TESTO);
                    datasource.createCategoria(name);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }




            Toast.makeText(this, "ho comunicato con un server!", Toast.LENGTH_LONG).show();  
            return mStartMode;
        }
        @Override
        public IBinder onBind(Intent intent) {
            // A client is binding to the service with bindService()
            return mBinder;
        }
        @Override
        public boolean onUnbind(Intent intent) {
            // All clients have unbound with unbindService()
            return mAllowRebind;
        }
        @Override
        public void onRebind(Intent intent) {
            // A client is binding to the service with bindService(),
            // after onUnbind() has already been called
        }
        @Override
        public void onDestroy() {
            datasource.close();
            // The service is no longer used and is being destroyed
        }


}
  • 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-16T15:09:57+00:00Added an answer on June 16, 2026 at 3:09 pm

    This happens because you are doing a network operation on the main thread, and this is not allowed on Android 3.0 and above. Even though it is in a service, services are run on the UI thread unless you specifically launch them in another thread or create a thread inside it.

    You can fix this by running the task in a service off the main UI thread, by using a Thread or an AsyncTask.

    Try creating a new thread in onStartCommand(), as suggested by @CommonsWare.

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

Sidebar

Related Questions

After trying to get a text from the database i got this error: 12-21
I'm working on a brand new website and I'm trying to just get the
I'm brand new to Prolog. I am simply trying to get some output from
after trying to get a multiple file selection input working with previews, but then
After trying this simple console input with 5, the result is shown as 53
After trying to get the mercurial repository explorer setup on my shared hosting with
I am trying to deploy a web service, written in VS2008 on a brand
I have just downloaded jQuery 1.7 for a brand new project I'm starting. After
SO I'm trying to get some work done in Excel 2013, and after getting
I'm brand new to rails and am trying to dive in to my first

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.