Note that there are some explanatory texts on larger screens.

plurals
  1. POLocationManager don't get the right results
    primarykey
    data
    text
    <p>I am using LocationManager to convert from lat,longi to get the city name, but I am getting wrong results, I think there is something wrong in this code here:</p> <pre><code>locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the locatioin provider -&gt; use // default Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected."); onLocationChanged(location); Log.d("msgh","msgh"); } else { System.out.println("location not available"); Log.d("msg","msg"); } </code></pre> <p>the code doesn't enter the if statement and always enters the else statement.</p> <p>after Editing, this is the logCat:</p> <pre><code>11-24 15:06:25.072: E/AndroidRuntime(6963): FATAL EXCEPTION: main 11-24 15:06:25.072: E/AndroidRuntime(6963): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.survivingwithandroid.weatherapp/com.survivingwithandroid.weatherapp.MainActivity}: java.lang.NullPointerException 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread.access$600(ActivityThread.java:141) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.os.Handler.dispatchMessage(Handler.java:99) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.os.Looper.loop(Looper.java:137) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread.main(ActivityThread.java:5103) 11-24 15:06:25.072: E/AndroidRuntime(6963): at java.lang.reflect.Method.invokeNative(Native Method) 11-24 15:06:25.072: E/AndroidRuntime(6963): at java.lang.reflect.Method.invoke(Method.java:525) 11-24 15:06:25.072: E/AndroidRuntime(6963): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 11-24 15:06:25.072: E/AndroidRuntime(6963): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 11-24 15:06:25.072: E/AndroidRuntime(6963): at dalvik.system.NativeStart.main(Native Method) 11-24 15:06:25.072: E/AndroidRuntime(6963): Caused by: java.lang.NullPointerException 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.location.GeocoderParams.&lt;init&gt;(GeocoderParams.java:50) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.location.Geocoder.&lt;init&gt;(Geocoder.java:83) 11-24 15:06:25.072: E/AndroidRuntime(6963): at com.survivingwithandroid.weatherapp.MainActivity.onCreate(MainActivity.java:227) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.Activity.performCreate(Activity.java:5133) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 11-24 15:06:25.072: E/AndroidRuntime(6963): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload