ユーザーが情報を投稿するために緯度と経度の場所を提供する必要があるアプリに取り組んでいます。問題は、次のコードを使用する場合です。
/********************************************************************
* GET LATITUDE *
********************************************************************/
public String getLatitude(){
LocationManager lm = (LocationManager) ACTIVITY.getSystemService(Context.LOCATION_SERVICE);
if( lm.isProviderEnabled( LocationManager.GPS_PROVIDER )){
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null){
return Double.toString( location.getLatitude() );
}
}
return null;
}
/********************************************************************
* GET LONGITUDE *
********************************************************************/
public String getLongitude(){
LocationManager lm = (LocationManager) ACTIVITY.getSystemService(Context.LOCATION_SERVICE);
if( lm.isProviderEnabled( LocationManager.GPS_PROVIDER )){
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null){
return Double.toString( location.getLongitude() );
}
}
return null;
}
次のエラー メッセージが表示されます。
12-06 22:31:46.791: W/dalvikvm(1173): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
12-06 22:31:46.811: E/AndroidRuntime(1173): FATAL EXCEPTION: main
12-06 22:31:46.811: E/AndroidRuntime(1173): java.lang.IllegalStateException: Could not execute method of the activity
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.view.View$1.onClick(View.java:3044)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.view.View.performClick(View.java:3511)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.view.View$PerformClick.run(View.java:14105)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.os.Handler.handleCallback(Handler.java:605)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.os.Handler.dispatchMessage(Handler.java:92)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.os.Looper.loop(Looper.java:137)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.app.ActivityThread.main(ActivityThread.java:4424)
12-06 22:31:46.811: E/AndroidRuntime(1173): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173): at java.lang.reflect.Method.invoke(Method.java:511)
12-06 22:31:46.811: E/AndroidRuntime(1173): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-06 22:31:46.811: E/AndroidRuntime(1173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-06 22:31:46.811: E/AndroidRuntime(1173): at dalvik.system.NativeStart.main(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173): Caused by: java.lang.reflect.InvocationTargetException
12-06 22:31:46.811: E/AndroidRuntime(1173): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173): at java.lang.reflect.Method.invoke(Method.java:511)
12-06 22:31:46.811: E/AndroidRuntime(1173): at android.view.View$1.onClick(View.java:3039)
12-06 22:31:46.811: E/AndroidRuntime(1173): ... 11 more
12-06 22:31:46.811: E/AndroidRuntime(1173): Caused by: java.lang.NullPointerException
12-06 22:31:46.811: E/AndroidRuntime(1173): at com.example.cay.saati.Helper.getLatitude(Helper.java:100)
12-06 22:31:46.811: E/AndroidRuntime(1173): at com.example.cay.saati.MenuPage.prepareLoginInformation(MenuPage.java:230)
12-06 22:31:46.811: E/AndroidRuntime(1173): at com.example.cay.saati.MenuPage.onClick(MenuPage.java:267)
12-06 22:31:46.811: E/AndroidRuntime(1173): ... 14 more
LocationManager を使用するには、次のアクセス許可を使用します。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
また、ライブラリ:
<uses-library android:name="com.google.android.maps" />
誰かが正確な問題を教えてもらえますか? java.lang.reflect.invocationTargetException の原因は何ですか? 理解できません。ありがとう!