java - GPS Application crash -


I have to write an application that does a lot of things including recording the user's GPS location, when a correct username and password Happens to enter I only want latitude and longitude in that exact moment, the recurring check of that nature or nothing. I think that whatever I was looking for, got anything like this:

However, Eclipse did not like the reference because I have not started it yet So that code of the whole code:

  reference reference = getBaseContext (); LocationManager locMan = (LocationManager) context.getSystemService (context.LOCATION_SERVICE); Logs. I (getclass (). GetSimpleName (), called "Location Manager"); Location loc = locMan.getLastKnownLocation (LocationManager.GPS_PROVIDER); Logs. I (getclass (). GetSimpleName (), "get last known location"); Double latitude = loc.getLatitude (); Log.i (getClass () getSimpleName (), "Latitude:" + Latitude.); Double longitude = loc.getLongitude (); Log.i (GetClass () getSimpleName (), "Longitude:" + Longitude); Toast. Make Text (Reference, Latitude + "," + Longitude, Toast. LNNHHLAG). Show ();  

and for permission in the manifest:

  Use of Android - permission: name = "com.foxcatch.code.insecure.LOCATION_FINDER" /> ; & Lt; Usage-permission Android: name = "android.permission.ACCESS_FINE_LOCATION" /> & Lt; Usage-permission Android: name = "android.permission.ACCESS_COARSE_LOCATION" />  

However, when I try to reach latitude and longitude and try to double them:

  double latitude = loc.getLatitude () ; Double longitude = loc.getLongitude (); Here is the logcat error entry, this is slightly on my head:  

04-28 18: 00: 39.346: E / Android time (32548) : Fatal Exception: Main 04-28 18: 00: 39.346: E / Android Random (32548): Process: com.rps.personaldata, PID: 32548 04-28 18: 00: 39.346: E / Android Random (32548): Java.lang .NullPointerException 04-28 18: 00: 39.346: E / Android Time (32548): at com.rps.personaldata. Click main activity $ 1.on (main activity. Java: 58) 04-28 18: 00: 39.346: E / Android Random (32548): At android.view.View.performClick (see Java: 4445) 04- 28 18: 00: 39.346: E / Android Random (32548): For Android. View.View $ PerformClick.run (see .Java 18429) 04-28 18: 00: 39.346: E / Android Random (32548): Android. On. Handler Handyley Callback (Handler. 733) 04-28 18: 00: 39.346: E / Android Random (32548): Os.Handler.DispatchMessage on Android (Handler. Java: 94) 04-28 18: 00: 39.346: E / Android Rendime (32548): Android.OS Lopper Loop (Looper.java:1236) 04-28 18:00: 39.346: E / Endoye Dirtime (32548): Android. App ActivateTrade.Mine (ActivityThovedJAdAd 81) 04-28 18: 00: 39.346: E / Android TimeTime (32548): at java.lang.reflect.Method.invokeNative (Basic Method) 04-28 18: 00: 39.346: E / Android Rantime (32548): java.lang.reflect.Method.invoke (Method Java Author) 04-28 18: 00: 39.346: E / Android Time (32548): at Com.android.internal.os.ZygoteInit $ MethodAndArgsCaller. Run (zygoteinit.java: 781) 04-28 18: 00: 39.346: E / Android timeTime (32548): com.android.internal.os.ZygoteInit.main (Zygoteint .java: 597) 04-28 18: 00: 39.346: E / Android Runtime (32548): On Dalvik.system.NativeStart.main (Basic method)

I I'm new to Droid, and I'm just trying to learn all this. Thanks for any help.

Why is getting the BaseContext .. just go directly getSystemService

Change it:

  Location Manager loc_en = (location manager) context.getSystemService (context.LOCATION_SERVICE); For           


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -