android - Can't succed to write in a database -
Hi! I am trying to create an application that receives GPS data for days and store it in SQLT database. I have created the database and I also have a geo point array list which I am putting in my geographic points. GPS data is now fake with the help of a KML file, my problem is that even though I succeeded to display the location that has been updated with the new location, when I try to read from the Sclit database And displaying on the screen, I do not get anything, no one is displayed on the screen.
Here is my code:
Map activity in public square screen 4 (Private Location Manager LM; Private locale location station; Private MyLocationOverlay myLocOverlay; see private map map map; Private Map controller MC; Override public zeroes on the list of & lt; GeoPoint & gt; GeoPointsArray = New ArrayList & gt; GeoPoint & gt; (); Int Latitude; Int Latitude; @Create {Bundle Saved InstantStat} {Super. Nakrat (Saved Instantstate); setContentView ( R.layout.screen4); Lm = (LocationManager) getSystemService (context.LOCATION_SERVICE); LocationListener = New MyLocationListener (); lm.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0,0, locationListener); MapView = (MapView) Find ViewById (R .id.mapview1); mapView.setBuiltInZoomControls (right); Mc = mapView.getController (); initMyLocation (); DBAdapter db = new DBAdapter (this); db.createDatabase (); for db.openDataBase () I = 0; i & lt; geoPointsArray.size () - 1; i ++) {geographic location = geoPointsArray.get (i); Db.insertData (Integer.toString (loc.getLongitudeE6 ()), Integer.toString (loc.getLatitudeE6 ()), zero, null, faucet); } Cursor c = db.getAllData (); If (c.moveToFirst) () {DisplayTitle (c); } While (c.moveToNext ()); } If (c! = Null & amp;; cisClosed ()) {db.close (); }} Private Zero Init Myelication () {myLocOverlay = New MyLocationOverlay (this, map view); MyLocOverlay.enableMyLocation (); . Adding MapView.getOverlays () (myLocOverlay); } Public Zero DisplayTitle (Cursor C) {Toast.makeText (This, "Longitude:" + c.getString (0) + "\ n" + "Latitude:" + c.getString (1) + "\ n", Toast .LENGTH_LONG) .show (); } Private class applies the MyLocationListener location laser {@Override changed the location to public zero (location location) {if (loc! = Null) {latitude = (int) (loc.getLatitude () * 1E6); Longitude = (int) (loc.getLongitude () * 1E6); Geopoint P = New GeoPoint (latitude, longitude); GeoPointsArray.add (P); Mc.animateTo (P); Mc.setZoom (17); MapView.invalidate (); MapView.setSatellite (right); }} Override public zero {// TODO auto-generated method stub} on @ProviderDisabled @ProviderEverabled {string} {} Override status switching (string provider, int status, bundle extras) on public zero { }} Protected Boolean Hydride Display () {// Tudo Auto-Generated Method Stub Return False; }} I debug my code line by line and as I get this line (the first one):
for ( Int i = 0; i & lt; geoPointsArray.size () - 1; i ++) {Geo-point people = Geo PointErray.Gate (I); Db.insertData (Integer.toString (loc.getLongitudeE6 ()), Integer.toString (loc.getLatitudeE6 ()), zero, null, faucet); } Debugger jumps to this snippet ... Now for me this means that I do not have any sense in my geo point array and I do not have any collection in the data base And there is nothing from reading here SQLite Can someone please help me with some ideas. Thanks
In general if must be guarded for arrays i & Lt; Size and i . You can use the Guard to avoid mistakes:
For (GeoPoint loc: geoPointsArray) {....
Edit - In addition, your database access is being done only in onCreate . You need to do this in your LocationListener if you receive updates you expect to call it. onCreate is said only once when your activity is created. You should open your database here and then get access to it when you actually get the data.
Comments
Post a Comment