I run the following code when getSystemService Ben will collapse.
package com.example.switchkeyboard;
import org.openintents.sensorsimulator.hardware.SensorEvent;
import org.openintents.sensorsimulator.hardware.SensorEventListener;
import org.openintents.sensorsimulator.hardware.SensorManagerSimulator;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
MyListener myListener;
Button Open = null;
Button Close = null;
org.openintents.sensorsimulator.hardware.Sensor sor = null;
SensorManagerSimulator imulatorManager;
TextView textView = null;
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
Open = (Button) findViewById (R.id.open);
Close = (Button) findViewById (R.id.close);
textView = (TextView) findViewById (R.id.textView);
/ / SenM = (SensorManager) getSystemService (Context.SENSOR_SERVICE);
/ / One run here on Ben collapse
imulatorManager = SensorManagerSimulator.getSystemService (this, SENSOR_SERVICE);
/ * ImulatorManager.connectSimulator ();
/ / Sor = imulatorManager.getDefaultSensor (Sensor.TYPE_ACCELEROMETER);
/ / Sor = (Sensor) imulatorManager.getDefaultSensor (Sensor.TYPE_ACCELEROMETER);
myListener = new MyListener ();
Open.setOnClickListener (new Button.OnClickListener () {
@ Override
public void onClick (View arg0) {
/ / TODO Auto-generated method stub
imulatorManager.registerListener (myListener, imulatorManager.getDefaultSensor (Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
}
});
* /
}
class MyListener implements SensorEventListener
{
public MyListener () {
/ / TODO Auto-generated constructor stub
}
@ Override
public void onSensorChanged (SensorEvent arg0) {
/ / TODO Auto-generated method stub
textView.setText (arg0.values [0] + "");
}
@ Override
public void onAccuracyChanged (
org.openintents.sensorsimulator.hardware.Sensor arg0, int arg1) {
/ / TODO Auto-generated method stub
}
}
@ Override
protected void onPause () {
/ / TODO Auto-generated method stub
super.onPause ();
imulatorManager.unregisterListener (myListener);
}
@ Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater () inflate (R.menu.activity_main, menu);.
return true;
}
}
Very wonder.
Now no clue. Originally, I would not be a bad environment configuration? But only in SensorManagerSimulator.getSystemService will go wrong?
We also hope to talk about the possibility of
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Error message? ? ? ? ? ? ? ? ?
Reply:
08-17 07:24:14.074: E / AndroidRuntime (885): Uncaught handler: thread main exiting due to uncaught exception
08-17 07:24:14.074: E / AndroidRuntime (885): java.lang.NoClassDefFoundError: org.openintents.sensorsimulator.hardware.SensorManagerSimulator
08-17 07:24:14.074: E / AndroidRuntime (885): at com.example.switchkeyboard.MainActivity.onCreate (MainActivity.java: 42)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1047)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2459)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 2512)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.access $ 2200 (ActivityThread.java: 119)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1863)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.os.Handler.dispatchMessage (Handler.java: 99)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.os.Looper.loop (Looper.java: 123)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.main (ActivityThread.java: 4363)
08-17 07:24:14.074: E / AndroidRuntime (885): at java.lang.reflect.Method.invokeNative (Native Method)
08-17 07:24:14.074: E / AndroidRuntime (885): at java.lang.reflect.Method.invoke (Method.java: 521)
08-17 07:24:14.074: E / AndroidRuntime (885): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 860)
08-17 07:24:14.074: E / AndroidRuntime (885): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 618)
08-17 07:24:14.074: E / AndroidRuntime (885): at dalvik.system.NativeStart.main (Native Method)
I've added SensorManagerSimulator. The compiler did not complain.
Reply:
08-17 07:24:14.074: E / AndroidRuntime (885): Uncaught handler: thread main exiting due to uncaught exception
08-17 07:24:14.074: E / AndroidRuntime (885): java.lang.NoClassDefFoundError: org.openintents.sensorsimulator.hardware.SensorManagerSimulator
08-17 07:24:14.074: E / AndroidRuntime (885): at com.example.switchkeyboard.MainActivity.onCreate (MainActivity.java: 42)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1047)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2459)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 2512)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.access $ 2200 (ActivityThread.java: 119)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1863)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.os.Handler.dispatchMessage (Handler.java: 99)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.os.Looper.loop (Looper.java: 123)
08-17 07:24:14.074: E / AndroidRuntime (885): at android.app.ActivityThread.main (ActivityThread.java: 4363)
08-17 07:24:14.074: E / AndroidRuntime (885): at java.lang.reflect.Method.invokeNative (Native Method)
08-17 07:24:14.074: E / AndroidRuntime (885): at java.lang.reflect.Method.invoke (Method.java: 521)
08-17 07:24:14.074: E / AndroidRuntime (885): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 860)
08-17 07:24:14.074: E / AndroidRuntime (885): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 618)
08-17 07:24:14.074: E / AndroidRuntime (885): at dalvik.system.NativeStart.main (Native Method)
I've added SensorManagerSimulator. The compiler did not complain.
Reply:
Have encountered such a problem, how to solve ah
Reply:
There may not have added to the project LIB ah
Reply:
Upstairs said should be resolved
No comments:
Post a Comment