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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:41:01+00:00 2026-06-16T19:41:01+00:00

I have made a service to get the app updated, it is started by

  • 0

I have made a service to get the app updated, it is started by a broadcast receiver that take broadcasts from the app and the boot of the system.

java.lang.NullPointerException happen.

java.lang.RuntimeException: Unable to instantiate service 
  com.ggservice.democracy.updateDemocracyService: java.lang.NullPointerException
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2237)
    at android.app.ActivityThread.access$1600(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.NullPointerException
    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:386)
    at android.accounts.AccountManager.get(AccountManager.java:288)
    at com.ggservice.democracy.updateDemocracyService.<init>(updateDemocracyService.java:33)
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1319)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2234)

the service is this:

public class updateDemocracyService extends IntentService{
    public updateDemocracyService() {
        super("updateDemocracyService");
        // TODO Auto-generated constructor stub
    }
    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
        AccountManager am = AccountManager.get(this); // "this" references the current Context

        //cerco un account per identificare l'utente.
        Account[] accounts = am.getAccountsByType("com.google");
        String nomeaccount = md5(accounts[0].name);


        private static String url = "http://lnx.ggservice.com/democracy/domande.php?user=" ;
        private static String risposteUrl = "http://lnx.ggservice.com/democracy/domande.php?useranswer=" ;

        // JSON Node names
        private static final String TAG_DOMANDE = "domande";
        private static final String TAG_ID = "idWeb";
        private static final String TAG_CATEGORIA = "categoria";
        private static final String TAG_TESTODOMANDA = "testoDomanda";
        private static final String TAG_QUANTERISPOSTE = "quanteRisposte";
        private static final String TAG_TESTORISPOSTA = "testoRisposta";
        private static final String TAG_OK = "ok";


        // contacts JSONArray
        JSONArray domanda = null;
        JSONArray rispostescritte = null;


        @SuppressWarnings("deprecation")
        @Override
        protected void onHandleIntent(Intent intent) {
            datasource = new pollDataSource(this);
            datasource.open();


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

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


            try {

                // Getting Array of Contacts
                domanda = json.getJSONArray(TAG_DOMANDE);

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

                    // Storing each json item in variable
                    String id = c.getString(TAG_ID);
                    String testoDomanda = c.getString(TAG_TESTODOMANDA);
                    String categoria = c.getString(TAG_CATEGORIA);
                    int quanteRisposte = c.getInt(TAG_QUANTERISPOSTE);


                    datasource.createCategoria(categoria);
                    //TEOTODO inserimento della categoria, se necessario
                    //TEOTODO inserimento della domanda



                    for(int ua = 0; ua < quanteRisposte; ua++){
                    //TEOTODO inserimento dei testi risposte.   

                    }


                    //NOTIFICATION
                   NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  

                   Notification note = new Notification(R.drawable.ic_launcher, "Democracy", System.currentTimeMillis());  

                   PendingIntent intent1 = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);  

                   note.setLatestEventInfo(this, "Nuovi sondaggi", "Ci sono nuovi sondaggi per te!!", intent1);  

                   int NOTIF_ID = 1;
                   notifManager.notify(NOTIF_ID, note);            
                   //NOTIFICATION    
                }
            } catch (JSONException e) {
              //  e.printStackTrace();
            }  

            //recupero tutte le risposte dal database, poi per ogni risposta:
            //JSONObject json1 = jParser.getJSONFromUrl(risposteUrl + nomeaccount); //+idweb+risposta

          //  try {

                // Getting Array of responses
               // rispostescritte = json.getJSONArray(TAG_OK);
          //      }   catch (JSONException e) {} 







             Intent i= new Intent(); 
             i.setAction("AWESOME_TRIGGER_WORD"); //the name which we will specify in our receiver 
             i.putExtra("counter",234); PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(),
             1111, i,PendingIntent.FLAG_CANCEL_CURRENT);
             //getting current time and add 5 seconds in it 
              Calendar cal = Calendar.getInstance(); 
              cal.add(Calendar.MINUTE, 10); 
              //registering our pending intent with alarmmanager 
              AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
              am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), pi);       


        }

        public String md5(String s) {
            try {
                // Create MD5 Hash
                MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
                digest.update(s.getBytes());
                byte messageDigest[] = digest.digest();

                // Create Hex String
                StringBuffer hexString = new StringBuffer();
                for (int i=0; i<messageDigest.length; i++)
                    hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
                return hexString.toString();

            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            return "";
        }


}

why a java.lang.NullPointerException ?
this is also the call that fire the service:

public class BootCompletedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {          
        Intent serviceIntent = new Intent(context, updateDemocracyService.class);
        context.startService(serviceIntent);         
    }
}
  • 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-16T19:41:02+00:00Added an answer on June 16, 2026 at 7:41 pm

    Replace

    AccountManager am = AccountManager.get(this); 
    

    with this

    AccountManager am = AccountManager.get(updateDemocracyService.this); 
    

    and it would better to initialize your variables in the onCreate() method of the service.

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

Sidebar

Related Questions

I have made a Windows Service that gets installed in a c:\Program Files\My Service
I have made a small log service that i want to publish to a
I have made a code that read data from flash Nand (without filesystem). fd
I have weird problem that I cant figure it out. I've made mobile app
I have made a Azure web app that has a ASP.NET web that also
I have designed a web service application and fetch app's data from my server
We have a C# client app that communicates to our C# backend service via
I have been made a windows service.in which i have been added project installer.in
I have just made a portlet with web service for liferay to learn how
I made a Web service in which I have a function to count some

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.