IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Erreur "java.lang.IllegalStateException: attempt to re-open an already-closed object"


Sujet :

Android

  1. #1
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut Erreur "java.lang.IllegalStateException: attempt to re-open an already-closed object"
    Salut,
    Je fais face à une erreur dont je ne connais pas l'origine:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    12-30 22:29:58.290: E/AndroidRuntime(22933): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.trainingcenter/com.example.trainingcenter.CalculDistance}: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, libellé, tel, email, adresse, ville, catégorie, latitude, longitude FROM table_formation)
    la classe CalculDistance qui calcule le plus proche point par rapport à la localisation de l'utilisateur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    public class CalculDistance extends MapActivity implements LocationListener {
    	double latitudeUser;
    	double longitudeUser;
    	FormationBDD formationBdd;
    	Formation formation;
     
    	MapView	mapView = null;
    	 private LocationManager lm = null;
    	MapController mc = null;
    	List<Formation> listF = new ArrayList<Formation>();
     
    	 public void onCreate(Bundle savedInstanceState) {
    		 super.onCreate(savedInstanceState);
    			setContentView(R.layout.localisation);
    			mapView = (MapView) this.findViewById(R.id.mapview);
    			mapView.setBuiltInZoomControls(true);
    			lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
    			lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this);
    			lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0,
    				this);
     
     
    			mc = mapView.getController();
    			mc.setZoom(15);
    		    formationBdd = new FormationBDD(this);
    		    formationBdd.open();
    		    listF = formationBdd.getAllFormations();
    		    Log.i(getClass().getName(), "la liste contient: " + listF);
     
    		    int indexdistanceMin = indexmindistance();
    		    double latitudemin = listF.get(indexdistanceMin).getLatitude();
    		    double longitudemin = listF.get(indexdistanceMin).getLongitude();
    		    GeoPoint point = new GeoPoint(microdegrees(latitudemin),microdegrees(longitudemin));
    		    ItemizedOverlayPerso pinOverlay = new ItemizedOverlayPerso(getResources().getDrawable(R.drawable.marker));
    			pinOverlay.addPoint(point);
    			mapView.getOverlays().add(pinOverlay);
     
    	 }
     
     
    		@Override
    		protected boolean isRouteDisplayed() {
    			// TODO Auto-generated method stub
    			return false;
    		}
     
    		 @Override
    		    public void onLocationChanged(Location location) {
    			latitudeUser = location.getLatitude();
    			longitudeUser = location.getLongitude();
     
    		}
     
    		@Override
    		public void onProviderDisabled(String provider) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void onProviderEnabled(String provider) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void onStatusChanged(String provider, int status, Bundle extras) {
    			// TODO Auto-generated method stub
     
    		}
    		private int microdegrees(double value){
    			return (int)(value*1000000);
    		}
    		public class ItemizedOverlayPerso extends ItemizedOverlay<OverlayItem> {
     
    		    private List<GeoPoint> points = new ArrayList<GeoPoint>();
     
    		    public ItemizedOverlayPerso(Drawable defaultMarker) {
    		        super(boundCenterBottom(defaultMarker));
    		    }
     
    		    @Override
    		    protected OverlayItem createItem(int i) {
    		        GeoPoint point = points.get(i);
    		        return new OverlayItem(point,"Titre", "Description");
    		    }
     
    		    @Override
    		    public int size() {
    		        return points.size();
    		    }
     
    		    public void addPoint(GeoPoint point) {
    		        this.points.add(point);
    		        populate();
    		    }
     
    		    public void clearPoint() {
    		        this.points.clear();
    		        populate();
    		    }
    }
    la fonction de récupération de la liste Formations (listF)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    public List<Formation> getAllFormations()
    	{
    		List<Formation> formations = new ArrayList<Formation>();
     
    		Cursor cursor = bdd.query(TABLE_FORMATION, new String[]{COL_ID, COL_LIB, COL_TEL, COL_EMAIL, COL_ADR, COL_VILLE, COL_CAT, COL_LAT, COL_LONG}, null, null, null, null, null);
    		cursor.moveToFirst();
     
    		while (!cursor.isAfterLast())
    		{
    			formations.add(cursorToFormation(cursor));
    			cursor.moveToNext();
    		}
     
    		cursor.close();
     
    		return formations;
    	}
    private Formation cursorToFormation(Cursor c){
     
    		if (c.getCount() == 0)
    			return null;
     
     
    		c.moveToFirst();
     
    		Formation formation = new Formation();
     
    		formation.set_id(c.getInt(NUM_COL_ID));
    		formation.setLibellé(c.getString(NUM_COL_LIB));
    		formation.setTel(c.getString(NUM_COL_TEL));
    		formation.setEmail(c.getString(NUM_COL_EMAIL));
    		formation.setAdresse(c.getString(NUM_COL_ADR));
    		formation.setVille(c.getString(NUM_COL_VILLE));
    		formation.setCatégorie(c.getString(NUM_COL_CAT));
    		formation.setLatitude(c.getDouble(NUM_COL_LAT));
    		formation.setLongitude(c.getDouble(NUM_COL_LONG));
    		//On ferme le cursor
     
     
     
    		return formation;
    	}
    Pouvez vous m'aider?
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

  2. #2
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut
    J'ai trouvé l'origine de l'erreur: en fait j'utilise un Cursor que j'ai deja fermé.
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 49
    Points : 49
    Points
    49
    Par défaut
    Bonjour,

    Je déterre le sujet car j'ai exactement la même logique de code et la même erreur mais en supprimant ce "cursor.close()", j'obtiens une boucle infini.

    Quelle pourrait en être les causes svp ?

  4. #4
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 49
    Points : 49
    Points
    49
    Par défaut
    en effet ma boucle ne s’arrêtait jamais et je récupérai toujours la même entrée car j'appelai plusieurs fois moveToFirst() dans mes 2 méthodes. après l'avoir commenté tout est parfait

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 30/01/2015, 11h36
  2. Réponses: 3
    Dernier message: 08/04/2013, 08h26
  3. Erreur JSF java.lang.IllegalStateException
    Par lamia89 dans le forum JSF
    Réponses: 3
    Dernier message: 08/05/2012, 14h42
  4. Réponses: 0
    Dernier message: 21/04/2011, 12h04
  5. Réponses: 0
    Dernier message: 17/09/2009, 08h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo