Sunday, October 31, 2010

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

No, assuming he doesn't get an error even earlier, I'm sure he gets a
ClassCastException on that line. That happens before it even checks
for the method. NoSuchMethodException is somewhat more esoteric

The advice he actually needs is beyond the scope of this group. But
I'll sum it up:

"Learn to use the debugger". Running it under the debugger, set up to
stop on RuntimeException and Error, would leave it stopped at the
problem line, with a ClassCastException on the stack, and thus neatly
answer your question for you, in far less time than it took to ask
this group. And that skill will pay off many times a day.

On Oct 31, 6:39 pm, davemac <davemac...@gmail.com> wrote:
> 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?
>
> - davewww.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