因此,我将当前位置与存储在数据库中的位置进行比较。一切正常,但是当我使用模拟器控件发送位置时,我无法使单元格静音。Logcat 说光标是 OutOfBounds
这是我的代码
Cursor cur=null;
cur=y.rawQuery("SELECT longitude FROM data",null);
cur.moveToFirst();
cr=y.rawQuery("SELECT latitude FROM data",null);
cr.moveToFirst();
while(!cr.isAfterLast()) {
arlist.add(cr.getDouble(cr.getColumnIndex("latitude")));
cr.moveToNext();
}
while(!cur.isAfterLast()) {
arrylist.add(cr.getDouble(cr.getColumnIndex("longitude")));
cur.moveToNext();
}
for(int i=0;i<arlist.size();i++){
Location locB = new Location("point B");
locB.setLatitude(arlist.get(i));
locB.setLongitude(arrylist.get(i));
float distance=loc.distanceTo(locB);
if(distance<5){
((AudioManager) getSystemService(AUDIO_SERVICE))
.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
else{
((AudioManager) getSystemService(AUDIO_SERVICE))
.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
}
这是我的日志猫
11-11 09:45:16.528: E/AndroidRuntime(692): FATAL EXCEPTION: main
11-11 09:45:16.528: E/AndroidRuntime(692): android.database.CursorIndexOutOfBoundsException: Index 20 requested, with a size of 20
11-11 09:45:16.528: E/AndroidRuntime(692): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:418)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.database.AbstractWindowedCursor.getDouble(AbstractWindowedCursor.java:86)
11-11 09:45:16.528: E/AndroidRuntime(692): at com.example.alert.service$MyLocationListener.onLocationChanged(service.java:90)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:237)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:170)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:186)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.os.Looper.loop(Looper.java:137)
11-11 09:45:16.528: E/AndroidRuntime(692): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-11 09:45:16.528: E/AndroidRuntime(692): at java.lang.reflect.Method.invokeNative(Native Method)
11-11 09:45:16.528: E/AndroidRuntime(692): at java.lang.reflect.Method.invoke(Method.java:511)
11-11 09:45:16.528: E/AndroidRuntime(692): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-11 09:45:16.528: E/AndroidRuntime(692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-11 09:45:16.528: E/AndroidRuntime(692): at dalvik.system.NativeStart.main(Native Method)