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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:59:03+00:00 2026-05-22T00:59:03+00:00

im trying to make an speedometer using the accelerometer but for some reason the

  • 0

im trying to make an speedometer using the accelerometer but for some reason the code is crashing can someone please tell me what is wrong and how to fix it
thank you

this is the red part in logcat:

05-14 13:03:55.826: INFO/ActivityManager(91): Start proc com.hanud.speedo for activity com.hanud.speedo/.speedometer: pid=2052 uid=10127 gids={}
05-14 13:03:56.806: DEBUG/AndroidRuntime(2052): Shutting down VM
05-14 13:03:56.806: WARN/dalvikvm(2052): threadid=1: thread exiting with uncaught exception (group=0x400207f0)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052): FATAL EXCEPTION: main
05-14 13:03:56.986: ERROR/AndroidRuntime(2052): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hanud.speedo/com.hanud.speedo.speedometer}: java.lang.ClassNotFoundException: com.hanud.speedo.speedometer in loader dalvik.system.PathClassLoader[/data/app/com.hanud.speedo-2.apk]
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.os.Looper.loop(Looper.java:123)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at java.lang.reflect.Method.invoke(Method.java:521)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at dalvik.system.NativeStart.main(Native Method)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052): Caused by: java.lang.ClassNotFoundException: com.hanud.speedo.speedometer in loader dalvik.system.PathClassLoader[/data/app/com.hanud.speedo-2.apk]
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-14 13:03:56.986: ERROR/AndroidRuntime(2052):     ... 11 more
05-14 13:03:57.017: WARN/ActivityManager(91):   Force finishing activity com.hanud.speedo/.speedometer
05-14 13:03:57.526: WARN/ActivityManager(91): Activity pause timeout for HistoryRecord{4382d820 com.hanud.speedo/.speedometer}
05-14 13:04:05.666: DEBUG/dalvikvm(1890): GC_EXPLICIT freed 4544 objects / 322792 bytes in 288ms
05-14 13:04:07.796: WARN/ActivityManager(91): Activity destroy timeout for HistoryRecord{4382d820 com.hanud.speedo/.speedometer}
05-14 13:04:12.016: INFO/ActivityManager(91): Start proc com.android.email for service com.android.email/.service.MailService: pid=2058 uid=10004 gids={3003, 1015}

and this is the code:

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class Speedometer extends Activity {

  Handler handler = new Handler();

  SensorManager sensorManager;
    TextView myTextView;

    float appliedAcceleration = 0;
    float currentAcceleration = 0;
    float velocity = 0;
    Date lastUpdate;    

    @Override
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.main);

      myTextView = (TextView)findViewById(R.id.myTextView);
      lastUpdate = new Date(System.currentTimeMillis());

      sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
      Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        sensorManager.registerListener(sensorEventListener,
                                       accelerometer,
                                       SensorManager.SENSOR_DELAY_FASTEST);


      Timer updateTimer = new Timer("velocityUpdate");
      updateTimer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
          updateGUI();
        }
      }, 0, 1000);
    }

    private void updateGUI() {
      // Convert from meters per second to miles per hour.
      final double mph = (Math.round(100*velocity / 1.6 * 3.6))/100;

      // Update the GUI
      handler.post(new Runnable() {
      public void run() {
          myTextView.setText(String.valueOf(mph) + "mph");
      }
    });
    }

  private void updateVelocity() {
      // Calculate how long this acceleration has been applied.
      Date timeNow = new Date(System.currentTimeMillis());
      long timeDelta = timeNow.getTime()-lastUpdate.getTime();
      lastUpdate.setTime(timeNow.getTime());

      // Calculate the change in velocity at the 
      // current acceleration since the last update. 
      float deltaVelocity = appliedAcceleration * (timeDelta/1000);
      appliedAcceleration = currentAcceleration;

      // Add the velocity change to the current velocity.
      velocity += deltaVelocity;
    }

  //private final SensorListener sensorListener = new SensorListener() {
  private final SensorEventListener sensorEventListener = new SensorEventListener() {
    double calibration = Double.NaN;



      public void onSensorChanged(SensorEvent event) {
        double x = event.values[0];
        double y = event.values[1];
        double z = event.values[2];

      double a = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); 

      if (calibration == Double.NaN)
        calibration = a;
      else {
        updateVelocity();
        currentAcceleration = (float)a;
      }
    }
      public void onAccuracyChanged(Sensor sensor, int accuracy) { }
  };
}
  • 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-05-22T00:59:04+00:00Added an answer on May 22, 2026 at 12:59 am

    You defined (probably in the android manifest) com.hanud.speedo.speedometer, while your activity’s name is Speedometer (with capital S).

    Just to make it clear – change the name of the activity in the Manifest file to Speedometer.

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

Sidebar

Related Questions

Im trying to make a universal parser using generic type parameters, but i can't
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat=server
I'm trying make one treeView with infinite subgroups. I can add my groups but
trying to make 5 curl childs for curl handler and defining them, but can't
Right now I'm trying make some browser based game. But I have little questions.
Trying to make 3 x 3 matrix multiplier but it gives out wrong output.
Trying to make some small changes to Apache's Velocity engine. Here's what I can
Trying to make a make generic select control that I can dynamically add elements
im trying make one replace in string from a array but this dont work
Trying to make a simple toggle menu, and I can't seem to hide/show the

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.