任何人都可以發現這段代碼有什麼問題嗎?這是我第一次使用的意圖:意向初學者
Intent intent = new Intent(this,XmlParserActivity.class);
String Postcode = returnedAddress.getPostalCode().toString();
intent.putExtra("postcode", Postcode);
,並在我的解析器我:
Intent intent = getIntent();
String Postcode = intent.getStringExtra("postcode");
URL url = new URL("http://new.myweather2.com/developer/forecast.ashx?uac=gcV3ynNdoV&output=xml&query=" + Postcode);
請注意,我的GPS是工作,我測試
的logcat:
04-01 21:07:25.514: E/AndroidRuntime(19408): FATAL EXCEPTION: main
04-01 21:07:25.514: E/AndroidRuntime(19408): java.lang.NullPointerException
04-01 21:07:25.514: E/AndroidRuntime(19408): at weather.app.WeatherApplicationActivity.onLocationChanged(WeatherApplicationActivity.java:116)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:228)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:176)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.os.Looper.loop(Looper.java:150)
04-01 21:07:25.514: E/AndroidRuntime(19408): at android.app.ActivityThread.main(ActivityThread.java:4293)
04-01 21:07:25.514: E/AndroidRuntime(19408): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 21:07:25.514: E/AndroidRuntime(19408): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 21:07:25.514: E/AndroidRuntime(19408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-01 21:07:25.514: E/AndroidRuntime(19408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-01 21:07:25.514: E/AndroidRuntime(19408): at dalvik.system.NativeStart.main(Native Method)
發生了什麼,你記錄任何價值,看看你得到什麼? – Snicolas 2012-04-01 19:30:25
希望你已經解決了你的問題 – Ishu 2012-04-02 03:00:08
你有一個空指針異常:E/AndroidRuntime(19408):java.lang.NullPointerException 04-01 21:07:25.514:E/AndroidRuntime(19408):at weather.app.WeatherApplicationActivity .onLocationChanged(WeatherApplicationActivity.java:116),你能指定哪一行嗎? – MahdeTo 2012-04-02 05:04:06