지오 코더 (Geocoder)에게 주소를 알려주지 못해서 문제가 발생했지만 그 이유는 모르겠습니다. IndexOutOfBoundsException가 :지오 코더가 꺼내지 않음 주소 :
public void button_address (View v){
//Create Geocoder
gc = new Geocoder(this, Locale.getDefault());
//The string pulled from the app to be used in the Geocoder
String loc = address.getText().toString();
//The list the Geocoder will fill
List<Address> add;
//Check to make sure there is a value in loc
Log.d(TAG, loc);
Log.d(TAG, "Before try/catch");
try {
//Request Gecoder return string loc with an address for add
add = gc.getFromLocationName(loc, 1);
add.isEmpty();
//Check to see if add is empty
if(add.isEmpty()){ Log.d(TAG, "ADD is empty"); }
double lat = add.get(0).getLatitude();
double lon = add.get(0).getLongitude();
Log.d(TAG, "lat:" + lat + ", long:" + lon);
} catch (IOException e) {
Toast toast = Toast.makeText(this, "Please Try Entering Another Address",
Toast.LENGTH_SHORT);
toast.show();
e.printStackTrace();
}
지금 여기 이렇게 빈 수익을 추가 한 다음 로그 캣에서 내가 얻을 사실에 기초 내 로그 캣
05-24 19:33:21.309: D/MainActivity(32508): 3111 world Dr, lake Buena vista, fl 32830
05-24 19:33:21.309: D/MainActivity(32508): Before try/catch
05-24 19:33:21.329: D/MainActivity(32508): ADD is empty
05-24 19:33:21.329: D/AndroidRuntime(32508): Shutting down VM
05-24 19:33:21.329: W/dalvikvm(32508): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
05-24 19:33:21.418: E/AndroidRuntime(32508): FATAL EXCEPTION: main
05-24 19:33:21.418: E/AndroidRuntime(32508): java.lang.IllegalStateException: Could not execute method of the activity
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.view.View$1.onClick(View.java:3591)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.view.View.performClick(View.java:4084)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.view.View$PerformClick.run(View.java:16966)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.os.Handler.handleCallback(Handler.java:615)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.os.Looper.loop(Looper.java:137)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 19:33:21.418: E/AndroidRuntime(32508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-24 19:33:21.418: E/AndroidRuntime(32508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-24 19:33:21.418: E/AndroidRuntime(32508): at dalvik.system.NativeStart.main(Native Method)
05-24 19:33:21.418: E/AndroidRuntime(32508): Caused by: java.lang.reflect.InvocationTargetException
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 19:33:21.418: E/AndroidRuntime(32508): at android.view.View$1.onClick(View.java:3586)
05-24 19:33:21.418: E/AndroidRuntime(32508): ... 11 more
05-24 19:33:21.418: E/AndroidRuntime(32508): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
05-24 19:33:21.418: E/AndroidRuntime(32508): at java.util.ArrayList.get(ArrayList.java:304)
05-24 19:33:21.418: E/AndroidRuntime(32508): ... 14 more
05-24 19:33:23.839: I/Process(32508): Sending signal. PID: 32508 SIG: 9
입니다 잘못된 인덱스 0, 크기는 0 내가 그 확신입니다 어떻게 든 지오 코더가 실패합니다. 매니페스트에서 인터넷 사용 권한을 가지고 있으며 인터넷이 웹 브라우저를 통해 에뮬레이터에서 작동하는지 확인했습니다.
바라기를 다른 사람들은 제가 놓친 간단한 문제를 볼 수 있습니다. 모든 도움을 주셔서 미리 감사드립니다.
당신은 arraylist 추가가 비어 있습니다. 이 gc.getFromLocationName (loc, 1)은 null을 반환합니다 – Raghunandan
왜 그것이 비어 있는지 잘 모르겠습니다. – user2381309
십자가 위치 loc를 한 번 확인하십시오. – Raghunandan