1

我正在开发一个从 android 手机获取传感器值的 android 应用程序,以便通过将这些值存储在数据库中的 Web 服务来使用这些值。我没有用于测试传感器值的真实设备,所以我使用了传感器模拟器 [http://code.google.com/p/openintents/wiki/SensorSimulator][1] 现在的问题是每次我运行活动我收到错误,这是活动的代码(我使用的是 API 15 Google API 平台:4.0.3)

import org.openintents.sensorsimulator.hardware.Sensor;
import org.openintents.sensorsimulator.hardware.SensorEvent;
import org.openintents.sensorsimulator.hardware.SensorEventListener;
import org.openintents.sensorsimulator.hardware.SensorManagerSimulator;


public class SimulationActivity extends Activity implements SensorEventListener {

private SensorManagerSimulator mSensorManager;
private Sensor mTemperature;
private TextView mTemperatureLabel;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mTemperatureLabel = (TextView) findViewById(R.id.temperature);

    mSensorManager = SensorManagerSimulator.getSystemService(this,SENSOR_SERVICE);
    mSensorManager.connectSimulator();

}

@Override
protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);
    mSensorManager.registerListener(this,
            mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_FASTEST);
    mSensorManager.registerListener(this,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_FASTEST);
    mSensorManager.registerListener(this,
            mSensorManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE),
            SensorManager.SENSOR_DELAY_FASTEST);
}

@Override
protected void onStop() {
    mSensorManager.unregisterListener(this);
    super.onStop();
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {
}


public void onSensorChanged(SensorEvent event) {

    switch (event.type) {
    case Sensor.TYPE_ORIENTATION: {
        Log.i("Sensor changed ", " Orientation ");
        mTemperatureLabel.setText("orientation");

    }
        break;
    case Sensor.TYPE_LIGHT: {
        Log.i("Sensor changed ", " light ");
        mTemperatureLabel.setText("light");
    }
        break;
    case Sensor.TYPE_TEMPERATURE: {
        Log.i("Sensor changed ", " temperature ");
        mTemperatureLabel.setText("temperature");

    }
        break;
    case Sensor.TYPE_PRESSURE: {
        Log.i("Sensor changed ", " pressure ");
        mTemperatureLabel.setText("pressure ");

    }
        break;
    }
} 
}

这是错误消息

11-14 18:49:57.123: E/AndroidRuntime(4351): FATAL EXCEPTION: main
11-14 18:49:57.123: E/AndroidRuntime(4351): java.lang.RuntimeException: Unable to instantiate      activity ComponentInfo{com.tunisietelecom.android/com.tunisietelecom.android.SimulationActivity}: java.lang.ClassNotFoundException: com.tunisietelecom.android.SimulationActivity
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.os.Looper.loop(Looper.java:137)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at java.lang.reflect.Method.invokeNative(Native Method)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at java.lang.reflect.Method.invoke(Method.java:511)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at dalvik.system.NativeStart.main(Native Method)
11-14 18:49:57.123: E/AndroidRuntime(4351): Caused by: java.lang.ClassNotFoundException: com.tunisietelecom.android.SimulationActivity
11-14 18:49:57.123: E/AndroidRuntime(4351):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
11-14 18:49:57.123: E/AndroidRuntime(4351):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
11-14 18:49:57.123: E/AndroidRuntime(4351):     ... 11 more
4

2 回答 2

1

我解决了这个问题。将库添加到类路径时,该库不会导出到手机。您需要转到 Proyect Properties -> Java Build Path -> Order and Export 并“勾选”您需要导出到手机的库。如果你不这样做,图书馆就不会在手机上,Android 也找不到它!!!

于 2015-05-13T11:08:50.593 回答
0

引起:java.lang.ClassNotFoundException:com.tunisietelecom.android.SimulationActivity

您是否在清单文件中声明了您的活动?

于 2012-11-14T19:39:58.287 回答