Sunday, October 31, 2010

[android-developers] Re: Can u help me to find the mistake? i can't run this program.

I'm going to guess that asking for the SEARCH_SERVICE and casting it
to a SensorManager is not going to go well for you. You're probably
getting a NoSuchMethodException, yes?

- dave
www.androidbook.com

On Oct 29, 12:01 am, 菠菜冬 <huabeiyipil...@gmail.com> wrote:
> package com.android.CirclingCounter;
>
> import java.util.List;
>
> 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.util.Log;
> import android.widget.TextView;
>
> public class CirclingCounter extends Activity {
>         private SensorManager mSensorManager01;
>         private TextView displayTextView;
>         int i=0;
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>                 displayTextView=(TextView)findViewById(R.id.display);
>                 displayTextView.setText(i);
>                 mSensorManager01=(SensorManager)getSystemService(Context.SEARCH_SERVICE);
>     }
>
>         private final SensorEventListener mSensorListener= new SensorEventListener()
>         {
>                 @Override
>                 public void onAccuracyChanged(Sensor sensor,int accuracy)
>                 {
>
>                 }
>                 @Override
>                 public void onSensorChanged(SensorEvent event)
>                 {
>                         if(event.sensor.getType()==Sensor.TYPE_ORIENTATION)
>                         {
>                                 float fPitchAngle=event.values[SensorManager.DATA_Y];
>                                 if(fPitchAngle<-120)
>                                 {
>                                         i++;
>                                         displayTextView.setText(i);
>                                 }
>                                 else
>                                 {
>
>                                 }
>                         }
>                 }
>         };
>         @Override
>         protected void onResume()
>         {
>                 List<Sensor> sensors=mSensorManager01.getSensorList(Sensor.TYPE_ORIENTATION);
>                 mSensorManager01.registerListener(mSensorListener,
> sensors.get(0),SensorManager.SENSOR_DELAY_NORMAL);
>                 super.onResume();
>         }
>         @Override
>         protected void onPause()
>         {
>                 mSensorManager01.unregisterListener(mSensorListener);
>                 super.onPause();
>         }
>
> }

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment