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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:01:33+00:00 2026-06-19T04:01:33+00:00

My SensorManager was working perfectly until today. I didn’t change any code, all I

  • 0

My SensorManager was working perfectly until today. I didn’t change any code, all I did was boot eclipse and now I am getting an error which forces my app to quit; here is what I get:

02-20 11:44:50.835: E/AndroidRuntime(23828): FATAL EXCEPTION: main
02-20 11:44:50.835: E/AndroidRuntime(23828): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.synlight_development.sleep_smart/com.synlight_development.sleep_smart.Sleep}: java.lang.NullPointerException
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread.access$700(ActivityThread.java:139)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.os.Looper.loop(Looper.java:137)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread.main(ActivityThread.java:4918)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at java.lang.reflect.Method.invokeNative(Native Method)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at java.lang.reflect.Method.invoke(Method.java:511)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at dalvik.system.NativeStart.main(Native Method)
02-20 11:44:50.835: E/AndroidRuntime(23828): Caused by: java.lang.NullPointerException
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:423)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at com.synlight_development.sleep_smart.Sleep$Accelerator.<init>(Sleep.java:173)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at com.synlight_development.sleep_smart.Sleep.onCreate(Sleep.java:104)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.Activity.performCreate(Activity.java:5048)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
02-20 11:44:50.835: E/AndroidRuntime(23828):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
02-20 11:44:50.835: E/AndroidRuntime(23828):    ... 11 more

And here is my sensor class:

public class Accelerator extends Service implements SensorEventListener
    {
        public Accelerator()
        {
            SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            if(sm.getSensorList(Sensor.TYPE_GYROSCOPE).size() != 0)
            {
                Sensor s = sm.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
                sm.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
            }
        }
        public void onAccuracyChanged(Sensor s, int i) 
        {

        }
}
  • 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-19T04:01:34+00:00Added an answer on June 19, 2026 at 4:01 am

    Move:

    SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    if(sm.getSensorList(Sensor.TYPE_GYROSCOPE).size() != 0)
    {
        Sensor s = sm.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
        sm.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
    }
    

    Into your Service’s onCreate(). getSystemService() is a method in Context, which the Service extends. However, you do not have a Context until onCreate() has been called. Therefore, this results in an NPE in the constructor.

    Also, make sure you’re starting the Service using startService(), and not creating a normal Java object from it

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

Sidebar

Related Questions

Is it the SensorManager API that i have to use to measure steps? Any
The following example is taken from internet. In all the example the code is
I'm working with android sensor data. My application use SensorManager.getRotationMatrixFromVector( mRotationMatrix , event.values); and
I'm working on a chunk of code that enables to the user to shake
I´m working with accelerometer and the first code is Shake detector: (Code1) if (sensor
The function SensorManager.getRotationMatrix(...) does not work in Android 3.0+. I have run the code
My source code is: import android.content.Context; import android.hardware.SensorManager; public class ShakeEvent implements SensorEventListener {
I run this code on the emulator to read temperature change, but it never
I'm working on Android applications which uses SensorManager for different purposes. During investigation I
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called

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.