안녕하세요^^ 류종택님 동영상 강의를 보다가 막히는 바람에
이렇게 도움을 요청합니다.
(류종택님^^; 제가 본방 사수는 못하지만;; 재방으로(?) 열심히 공부하고 있습니다. 항상 감사합니다!)
GPS 수업이 상당히 흥미로웠는데..
한가지 문제가 발생했네요..
_locatino.requestLocationUpdates(,,,,); 이 함수를 호출하게 되면,
SORRY! ...has stopped unexpectedly. Please try again. 문구가 뜨면서 실행이 되지 않네요..
제가 뭔가 환경적으로 잘못 했나본데..그게 도통 무엇인지 모르겠습니다.. 영상에서 나온대로 잘 따라해봤어요^^;
혹시 설정에서 Use GPS satellites 도 해제했고.. 구글 Maps apk도 설치해뒀는데.. 왜 이런지 잘 모르겠네요,
아래는 LogCat 내용입니다.
06-21 01:25:46.575: DEBUG/AndroidRuntime(1601): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-21 01:25:46.575: DEBUG/AndroidRuntime(1601): CheckJNI is ON
06-21 01:25:46.847: DEBUG/AndroidRuntime(1601): --- registering native functions ---
06-21 01:25:47.897: DEBUG/AndroidRuntime(1601): Shutting down VM
06-21 01:25:47.907: DEBUG/dalvikvm(1601): Debugger has detached; object registry had 1 entries
06-21 01:25:47.936: INFO/AndroidRuntime(1601): NOTE: attach of thread 'Binder Thread #3' failed
06-21 01:25:48.637: DEBUG/AndroidRuntime(1609): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-21 01:25:48.637: DEBUG/AndroidRuntime(1609): CheckJNI is ON
06-21 01:25:48.927: DEBUG/AndroidRuntime(1609): --- registering native functions ---
06-21 01:25:50.007: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=kkh.begginer/.Main }
06-21 01:25:50.075: INFO/ActivityManager(60): Start proc kkh.begginer for activity kkh.begginer/.Main: pid=1615 uid=10033 gids={1015}
06-21 01:25:50.097: DEBUG/AndroidRuntime(1609): Shutting down VM
06-21 01:25:50.107: DEBUG/dalvikvm(1609): Debugger has detached; object registry had 1 entries
06-21 01:25:50.167: INFO/AndroidRuntime(1609): NOTE: attach of thread 'Binder Thread #3' failed
06-21 01:25:51.325: DEBUG/AndroidRuntime(1615): Shutting down VM
06-21 01:25:51.325: WARN/dalvikvm(1615): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): FATAL EXCEPTION: main
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): java.lang.RuntimeException: Unable to start activity ComponentInfo{kkh.begginer/kkh.begginer.Main}: java.lang.IllegalArgumentException: provider==null
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.os.Looper.loop(Looper.java:123)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at dalvik.system.NativeStart.main(Native Method)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): Caused by: java.lang.IllegalArgumentException: provider==null
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:625)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at kkh.begginer.Main.onCreate(Main.java:42)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): ... 11 more
06-21 01:25:51.376: WARN/ActivityManager(60): Force finishing activity kkh.begginer/.Main
06-21 01:25:51.878: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{43f05320 kkh.begginer/.Main}
06-21 01:25:54.646: INFO/Process(1615): Sending signal. PID: 1615 SIG: 9
06-21 01:25:54.676: INFO/ActivityManager(60): Process kkh.begginer (pid 1615) has died.
06-21 01:25:54.776: WARN/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43f4f338
06-21 01:26:02.276: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{43f05320 kkh.begginer/.Main}
그리고 다른 분의 GPS 예제를 가지고도 실행오류가 발생하더군요..
같은 함수에서 말이죠.. 답답합니다 ㅠ
헬프미!! 프리즈!!
이렇게 늦은시각에도 관심을 가져주셔서 감사합니다^^
아래가 전체 코딩된 소스이구요(류종택님이 강의하실때 쓴 소스 그대로입니다..)
location.requestLocationUpdates(_BestProvider, 2000, 10, this);
-> 이 부분이 오류가 난 거 같은데.. 에러가 왜 나는지 도통 모르겠네요...
제 컴퓨터 환경에서만 그런건지.. 아.. 안드로이드 2.2 입니다..
package kkh.begginer;
import java.io.IOException;
import java.util.Iterator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity implements LocationListener {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_btOpenMap = (Button) findViewById(R.id.btOpenMap);
_btOpenMap.setOnClickListener(on_OpenMap);
_TextView = (TextView) findViewById(R.id.TextView);
_tvGeoInfo = (TextView) findViewById(R.id.tvGeoInfo);
location = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria _Criteria = new Criteria();
_Criteria.setAccuracy(Criteria.NO_REQUIREMENT);
_Criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
String _BestProvider = location.getBestProvider(_Criteria, true);
location.requestLocationUpdates(_BestProvider, 2000, 10, this);
}
public void onProviderEnabled(String provider) {
_TextView.setText("onProviderEnabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onLocationChanged(Location location) {
_Latitude = location.getLatitude();
_Longitude = location.getLongitude();
_Altitude = location.getAltitude();
_TextView.setText(String.format("위도: %f, 경도: %f, 고도: %f", _Latitude, _Longitude, _Altitude));
_tvGeoInfo.setText(get_Geocode(_Latitude, _Longitude));
}
public void onProviderDisabled(String provider) {
_TextView.setText("onProviderDisabled");
}
private Button _btOpenMap = null;
private TextView _TextView = null;
private TextView _tvGeoInfo = null;
private LocationManager location = null;
private double _Latitude = 0;
private double _Longitude = 0;
private double _Altitude = 0;
private String get_Geocode(double ALatitude, double ALongitude) {
String _Result = "";
Geocoder _Geocoder = new Geocoder(this);
try {
Iterator<Address> _Addresses = _Geocoder.getFromLocation(ALatitude, ALongitude, 3).iterator();
if (_Addresses != null) {
while (_Addresses.hasNext()) {
Address namedLoc = _Addresses.next();
String placeName = namedLoc.getLocality();
String featureName = namedLoc.getFeatureName();
String country = namedLoc.getCountryName();
String road = namedLoc.getThoroughfare();
_Result += String.format("\n[%s][%s][%s][%s]", placeName, featureName, road, country);
int addIdx = namedLoc.getMaxAddressLineIndex();
for (int idx = 0; idx <= addIdx; idx++){
String addLine = namedLoc.getAddressLine(idx);
_Result += String.format("\nLine %d: %s", idx, addLine);
}
}
}
return _Result;
} catch (IOException e) {
return "Error";
}
}
private void do_OpenMap(double ALatitude, double ALongitude) {
Uri _GeoURI = Uri.parse(String.format("geo:%f,%f", ALatitude, ALongitude));
Intent geoMap = new Intent(Intent.ACTION_VIEW, _GeoURI);
startActivity(geoMap);
}
private View.OnClickListener on_OpenMap = new View.OnClickListener() {
public void onClick(View v) {
do_OpenMap(_Latitude, _Longitude);
// do_OpenMap(37.664054,127.040667);
}
};
}
아래와 같은 에러가 발생하네요..(잘 볼 줄은 모르나.. 권한에서도 문제가 발생??하는듯..)
많이 가르쳐주셔서 감사합니다^^ 일단 GPS는 이론적으로 익혀야겠군요..
좀더 안드로이드 개발 공부를 하면서 해결해 나가야겠습니다..ㅠㅠ
늦은시각에 정말 감사합니다.^^
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): java.lang.RuntimeException: Unable to start activity ComponentInfo{kkh.begginer/kkh.begginer.Main}: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION permission
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.os.Looper.loop(Looper.java:123)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at dalvik.system.NativeStart.main(Native Method)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): Caused by: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION permission
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.os.Parcel.readException(Parcel.java:1247)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.os.Parcel.readException(Parcel.java:1235)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:516)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.location.LocationManager._requestLocationUpdates(LocationManager.java:711)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:630)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at kkh.begginer.Main.onCreate(Main.java:42)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-21 02:53:58.286: ERROR/AndroidRuntime(1942): ... 11 more
06-21 01:25:51.347: ERROR/AndroidRuntime(1615): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:625)