E/SensorManager(9503): thread start
E/SensorManager(9503): =======>>> Sensor Thread Running <<<========
D/memalloc(9503): ion:
Mapped buffer base:0x53812000 size:4096000 offset:0 fd:71
D/memalloc(9503): ion:
Mapped buffer base:0x542ca000 size:4096000 offset:0 fd:77
W/IInputConnectionWrapper(9503):
getSelectedText on inactive InputConnection
D/memalloc(9503): ion: Unmapping buffer base:0x53ee2000 size:4096000
D/memalloc(9503): ion: Unmapping buffer base:0x53812000 size:4096000
W/IInputConnectionWrapper(9503): setComposingText on inactive InputConnection
W/dalvikvm(9503):
threadid=1: thread exiting with uncaught exception (group=0x40c1b1f8)
E/AndroidRuntime(9503): FATAL EXCEPTION: main
E/AndroidRuntime(9503): java.lang.NullPointerException
E/AndroidRuntime(9503):
at com.example.nam.run.onSensorChanged(run.java:133)
E/AndroidRuntime(9503):
at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:635)
E/AndroidRuntime(9503):
at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(9503):at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(9503):
at android.app.ActivityThread.main(ActivityThread.java:4512)
E/AndroidRuntime(9503):
at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(9503):
at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(9503):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
E/AndroidRuntime(9503):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
E/AndroidRuntime(9503):
at dalvik.system.NativeStart.main(Native Method)
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
long currentTime = System.currentTimeMillis();
long gabOfTime = (currentTime - lastTime);
if (gabOfTime > 1) {
lastTime = currentTime;
x = event.values[SensorManager.DATA_X];
y = event.values[SensorManager.DATA_Y];
z = event.values[SensorManager.DATA_Z];
speeds = Math.abs(x + y + z - lastX - lastY - lastZ) / gabOfTime
* 1;
if (speeds > SHAKE_THRESHOLD) {
// 이벤트 발생!!
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);// 정확도
criteria.setPowerRequirement(Criteria.POWER_LOW); // 전원 소비량
criteria.setAltitudeRequired(true); // 고도 사용여부
criteria.setBearingRequired(true); //
criteria.setSpeedRequired(true); // 속도
criteria.setCostAllowed(true); // 금전적비용
String provider = locationManager.getBestProvider(criteria,true);
Location location = locationManager.getLastKnownLocation(provider);
double latitude = location.getLatitude(); // 위도
double longitude = location.getLongitude(); // 경도
Geocoder gcK = new Geocoder(getApplicationContext(),Locale.KOREA);
if (startTime == -1) {startTime = location.getTime();
}// 현재 위치 거리 및 속도 구하기.
float distance[] = new float[1];
Location.distanceBetween(beforeLocation.getLatitude(), beforeLocation.getLongitude(),
location.getLatitude(), location.getLongitude(), distance);
long delay = location.getTime() - startTime;
double speed = distance[0]/delay;
double speedKMH = speed * 3600;
// 전 위치 저장.
beforeLocation = location;
if(speedKMH > 1) {
try {
List<Address> addresses = gcK.getFromLocation(latitude,longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
for (Address addr : addresses) {
sb.append(addr.getMaxAddressLineIndex() .insert(0, "-살려주세요-\n");
for (int i = 0; i < addr.getMaxAddressLineIndex(); i++)
sb.append(addr.getAddressLine(i)).append("<< \n\n");
}
Address address = addresses.get(0);
sb.delete(7, 8);
sb.append(address.getCountryName()).append(" ");
//sb.append(address.getPostalCode()).append(" ");
sb.append("경상북도").append(" "); // 가라코드
sb.append(address.getLocality()).append(" ");
sb.append(address.getThoroughfare()).append(" ");
sb.append(address.getFeatureName()).append("\n");
// sb.append(tStr).append("\n");
// sb.append(tStrLocal).append("\n");
Toast.makeText(getBaseContext(), sb.toString(),
Toast.LENGTH_SHORT).show();
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(text, null, sb.toString()
+ "에서 사고발생. 구조를 요청합니다. ", null, null);
setContentView(R.layout.not_safe);
// finish();
}
}
위 노란 글씨 부분에 경위도 갑을 못 받아서
실행시 계속 오류가 납니다; 다른 해결책 없을 까요??
구글링해서 개발자분들의 블로그 글도 참고하고 몇일째 수정해보지만
생초보라 그런지 막막합니다.
어떻게 코드를 적어넣어야 하나요?? 도와주세요.