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

  • Home
  • SEARCH
  • 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 7878501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:40:45+00:00 2026-06-03T03:40:45+00:00

I am developing an android application in which i want to use accelerometer. But

  • 0

I am developing an android application in which i want to use accelerometer.
But whenever i call the method :

SensorManager sm = (SensorManager)context.getSystemService(Context.SEARCH_SERVICE);

my application crashes.

My code is :

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    context = getApplicationContext();
    SensorManager sm = (SensorManager)context.getSystemService(Context.SEARCH_SERVICE);
    if(sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size()!=0)
    {

        Sensor s = sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
        sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
    }

    x = y = sensorX = sensorY = 0;

}

I done search on web but unable to find any solution. I am debugging my application on phone not on emulator. Kindly help me in this regard that why it crashes and how can i fix it.

following are the log cat errors :
05-02 06:40:04.299: W/dalvikvm(9525): threadid=1: thread exiting with uncaught exception (group=0x40018578)

   05-02 06:40:04.309: E/AndroidRuntime(9525): FATAL EXCEPTION: main
   05-02 06:40:04.309: E/AndroidRuntime(9525): java.lang.RuntimeException: Unable to     start activity ComponentInfo{com.accelerometer/com.accelerometer.AccelerometerActivity}: java.lang.ClassCastException: android.app.SearchManager

   05-02 06:40:04.309: E/AndroidRuntime(9525):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.os.Handler.dispatchMessage(Handler.java:99)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.os.Looper.loop(Looper.java:123)

  05-02 06:40:04.309: E/AndroidRuntime(9525):   at android.app.ActivityThread.main(ActivityThread.java:3687)

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at java.lang.reflect.Method.invokeNative(Native Method)

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at java.lang.reflect.Method.invoke(Method.java:507)

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at dalvik.system.NativeStart.main(Native Method)

 05-02 06:40:04.309: E/AndroidRuntime(9525): Caused by: java.lang.ClassCastException: android.app.SearchManager

 05-02 06:40:04.309: E/AndroidRuntime(9525):    at com.accelerometer.AccelerometerActivity.onCreate(AccelerometerActivity.java:24)

05-02 06:40:04.309: E/AndroidRuntime(9525):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

05-02 06:40:04.309: E/AndroidRuntime(9525):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

Thanks.

  • 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-03T03:40:47+00:00Added an answer on June 3, 2026 at 3:40 am
    SensorManager sm = (SensorManager)context.getSystemService(Context.SEARCH_SERVICE);
    

    This returns a SearchManager from getSystemService() and you cannot convert a SearchManager to a SensorManager, close but not quite the same…

    To get the SensorManager try this: (Taken from the Dev Guide)

     public SensorActivity() {
         mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
         mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android application which makes use of the Osmdroid maps api.
I'm currently developing an application for Android which needs to use a custom made
I am developing a soundboard application in which I use Listview Activity. But since
I am developing a soundboard application in which I use Listview Activity. But since
I developing an android application in which i want to integrate faceebook and twitter.
I am developing an android application in which I want to slide images with
I am developing an android application in which I want to get UDID of
I am developing an android application which involves parsing.I want to pass parameters to
I am developing android application in which i want to convert html code in
I am developing one Android application which communicate with Wifi network. I want to

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.