我得到一个崩溃onLocationChanged()
方法,这是我在logcat中得到
04-10 00:51:43.354: E/AndroidRuntime(4132): FATAL EXCEPTION: main
04-10 00:51:43.354: E/AndroidRuntime(4132): Process: com.dd.assistant, PID: 4132
04-10 00:51:43.354: E/AndroidRuntime(4132): java.lang.NullPointerException
04-10 00:51:43.354: E/AndroidRuntime(4132): at com.twixkat.assistant.MainActivity.onLocationChanged(MainActivity.java:1314)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.os.Handler.dispatchMessage(Handler.java:102)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.os.Looper.loop(Looper.java:136)
04-10 00:51:43.354: E/AndroidRuntime(4132): at android.app.ActivityThread.main(ActivityThread.java:5081)
04-10 00:51:43.354: E/AndroidRuntime(4132): at java.lang.reflect.Method.invokeNative(Native Method)
04-10 00:51:43.354: E/AndroidRuntime(4132): at java.lang.reflect.Method.invoke(Method.java:515)
04-10 00:51:43.354: E/AndroidRuntime(4132): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-10 00:51:43.354: E/AndroidRuntime(4132): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-10 00:51:43.354: E/AndroidRuntime(4132): at dalvik.system.NativeStart.main(Native Method)
和方法:
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
List<Address> addresses = null;
if (arg0 != null) {
double longitude = arg0.getLongitude();
double latitude = arg0.getLatitude();
Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
citylb.setText(addresses.get(0).getLocality());
getWeather((String) citylb.getText());
// if (addresses.size() > 0) return addresses.get(0).getLocality();
}
}
我跟着一些教程,我不知道为什么应用程序崩溃! 谢谢!!