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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:34:12+00:00 2026-06-12T19:34:12+00:00

My Intent Service is not starting. It is giving an error. I’m new to

  • 0

My Intent Service is not starting. It is giving an error. I’m new to android. I’m working in restful web api. I’m consume service on android device. I created a synchronization module in which if there is no covered area app will store data in database and check after every 60 second for network.

When it goes online it will upload data on server. I want this process to run in the background. for this purpose I used Intent Service which runs in background and notify user after execution. But service is not starting I checked many tutorial on net in which they were same method. but mine is not working.

<p><b>Below is my error code</b><p>
    <code> 
    10-11 11:45:30.734: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    10-11 11:45:30.774: E/AndroidRuntime(396): FATAL EXCEPTION: main
    10-11 11:45:30.774: E/AndroidRuntime(396): java.lang.RuntimeException: Unable to instantiate service com.remote.synchronizer.haris.OfflineDataService: java.lang.NullPointerException
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:1929)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.ActivityThread.access$2500(ActivityThread.java:117)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.os.Handler.dispatchMessage(Handler.java:99)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.os.Looper.loop(Looper.java:123)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at java.lang.reflect.Method.invokeNative(Native Method)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at java.lang.reflect.Method.invoke(Method.java:507)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at dalvik.system.NativeStart.main(Native Method)
    10-11 11:45:30.774: E/AndroidRuntime(396): Caused by: java.lang.NullPointerException
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.content.ContextWrapper.getSystemService(ContextWrapper.java:363)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:742)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at com.remote.synchronizer.haris.OfflineDataService.<init>(OfflineDataService.java:23)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at java.lang.Class.newInstanceImpl(Native Method)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at java.lang.Class.newInstance(Class.java:1409)
    10-11 11:45:30.774: E/AndroidRuntime(396):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:1926)
    10-11 11:45:30.774: E/AndroidRuntime(396):  ... 10 more

    </code>
    <p><b>Intent Service</b></p>

    <code><pre>
    package com.remote.synchronizer.haris;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.http.NameValuePair;

import android.app.AlertDialog;
import android.app.IntentService;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class OfflineDataService extends IntentService {

    boolean wifi,edge;
    private Timer timer= new Timer();
    SQLiteDatabase db;
    String un,shop,city,date,order,InsertQuery;
    AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);

    public OfflineDataService() {
        super("OfflineDataService");
    }

    /*@Override   
    public void onCreate() {

        super.onCreate();
         Log.e("Service Example", "Service Started.. ");

        db= openOrCreateDatabase("Product", MODE_PRIVATE, null);
        db.execSQL("CREATE TABLE IF NOT EXISTS Order (UserName VARCHAR(10), Shop VARCHAR(15), City VARCHAR(15), Date VARCHAR(10), Order VARCHAR(50));");

    }   */

    @Override
    protected void onHandleIntent(Intent intent) {

        Bundle bundle=intent.getExtras();
        un=bundle.getString("un");
        shop=bundle.getString("shop");
        city=bundle.getString("city");
        date=bundle.getString("date");
        order=bundle.getString("order");

        /*InsertQuery="INSERT INTO Order VALUES ('"+ un + "','"+ shop + "','" + city + "','" + date + "','" + order + "');";
        db.execSQL(InsertQuery);*/

        /*timer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {

                //Checking network connectivity
                   wifi=NetworkInfo.Wifi(OfflineDataService.this);
                   edge=NetworkInfo.EDGE(OfflineDataService.this);

                       if(wifi==true||edge==true)
                       {
                           DataSender();
                       }
                       else
                       {

                           dlgAlert.setMessage("Testing");
                           dlgAlert.show();
                           //  Toast toast=Toast.makeText(getApplicationContext(), "Testing", toast.LENGTH_LONG).show();
                       }
            }

        }, 1000, 5000);*/


    }

    /*@Override
    public void onDestroy() {

        super.onDestroy();
        Log.e("Service Example", "Service Destroyed.. ");

        //notifications
    }

    private void DataSender()
    {
        timer.cancel();

    }*/

}

</code></pre>

<p><b>Calling Method</b></p>

<code><pre>

 Intent serviceIntent= new Intent(this, OfflineDataService.class);
               Bundle bundle= new Bundle();
               bundle.putString("un", msg);
               bundle.putString("shop", shop.getText().toString());
               bundle.putString("city", city.getText().toString());
               bundle.putString("date", reportDate);
               bundle.putString("order", order.getText().toString());

               serviceIntent.putExtras(bundle);
               startService(serviceIntent);
</code></pre>

<p><b>AndroidManifest Declaration</b></p>

<code><pre>
android:enabled="true" 
android:name=".OfflineDataService"   
</code></pre>

<p>what is wrong in my code?</p>
<h3><b>Thanks in advance</b></h3>
  • 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-12T19:34:13+00:00Added an answer on June 12, 2026 at 7:34 pm

    1/ you cannot use an alertdialog from a service.

    2/ even in an Activity, you cannot use it for a Context before onCreate() (that is, you cannot use it in the instanciation process – not in the contstructor, and not in the member declaration)

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

Sidebar

Related Questions

After finding that starting a new intent might not be the right way to
Typically you start a service like this Intent i = new Intent(context,MessageService.class); context.startService(i); but
Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every
I've been studying from the book Pro Android 2. I'm working through a Service
I am using Intent Service in my program. In the Intent Service, I have
Why is it suggested generally to pass a pending intent for an Intent Service
I have two relatively simple codes. One main activity and one intent service. Main
I am getting this exception in the LogCat: Unable to start service Intent {
I have a Service that sends an Intent to my Activity every 0.1 seconds.
Is it possible to send an intent only to one service when this one

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.