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 "FATAL EXCEPTION: main"


Sujet :

Android

  1. #21
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonsoir,
    J'arrives à corriger l'ancienne faute.
    Maintenant , j'ai un problème au niveau de cette instruction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.myList = extras.getArray("myList");
    Elle est marquée en rouge (fausse) et je n'est pas pu la corriger.
    Aidez moi s'il vous plait et merci d'avance.

  2. #22
    Membre actif
    Inscrit en
    Décembre 2008
    Messages
    280
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 280
    Points : 261
    Points
    261
    Par défaut
    tu en vois le bout ! ça devrait fonctionner avec ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    extras.getParcelableArray("myList")
    Paye Tes Dettes - Applciation android.

    DevHackSecure - Pense bête d'un étudiant en informatique - Tutos DEV

    " I also realize that _everybody_ thinks that they are right, and that they are supported by all other right-thinking people. That's just how people work. We all think we're better than average." Linus Torvalds

  3. #23
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Merci pour votre aide .
    La faute a été corrigée mais l'activité ne fonctionne pas .
    Quelqu'un m'aidez s'il vous plait . Je suis débutante dans la manipulation des parcelables.
    Voici mes classes java.
    Place.java:
    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
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    package com.example.projet_fin_etude;
    import android.os.Parcel;
    import android.os.Parcelable;
     
    public class Place implements Comparable<Place> ,Parcelable   {
     
     
    	/**
             * 
             */
     
    	private String reference;
    	private String nom;
    	private String adresse ;
    	private double latitude ;
    	private double longitude;
    	private int distance;
    	public Place()
    	{
     
    	}
    	public Place(String reference,String nom,String adresse,double latitude, double longitude, int distance)
    	{
    		this.reference=reference;
    		this.nom=nom;
    		this.adresse=adresse;
    		this.latitude=latitude;
    		this.longitude=longitude;
    		this.distance=distance;
     
    	}
     
     
     
    	public String getReference() {
    		return reference;
    	}
     
    	public void setReference(String reference) {
    		this.reference = reference;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getAdresse() {
    		return adresse;
    	}
     
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
    	public double getLatitude() {
    		return latitude;
    	}
     
    	public void setLatitude(double latitude) {
    		this.latitude = latitude;
    	}
    	public double getLongitude() {
    		return longitude;
    	}
     
    	public void setLongitude(double longitude) {
    		this.longitude = longitude;
    	}
    	public int getDistance() {
    		return distance;
    	}
     
    	public void setDistance(int distance) {
    		this.distance = distance;
    	}
     
    	@Override
    	public int compareTo(Place p) {
    		// TODO Auto-generated method stub
    		if((this.distance)<p.getDistance())
    			return -1;
    		else if((this.distance)>p.getDistance())
    			return 1;
    		else
    		return 0;
    	}
     
    	@Override
    	public int describeContents() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
     
    	@Override
    	public void writeToParcel(Parcel dest, int flags) {
    		// TODO Auto-generated method stub
    		dest.writeString(reference);
    		dest.writeString(nom);
    		dest.writeString(adresse);
    		dest.writeDouble(latitude);
    		dest.writeDouble(longitude);
    		dest.writeInt(distance);
    	}
     
        public static final Parcelable.Creator<Place> CREATOR
                = new Parcelable.Creator<Place>() {
            public Place createFromParcel(Parcel in) {
                return new Place(in);
            }
     
            public Place[] newArray(int size) {
                return new Place[size];
            }
        };
        public Place(Parcel in) {
    		// TODO Auto-generated constructor stub
    		reference=in.readString();
    		nom=in.readString();
    		adresse=in.readString();
    		latitude=in.readDouble();
    		longitude=in.readDouble();
    		distance=in.readInt();
    	}
     
     
     
    }
    MaqueurActivity .java:
    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
    103
    104
    105
    106
    107
    108
    @Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		switch (item.getItemId()) {
    		case R.id.menu_trie:
     
    			   Intent intent = new Intent(MarqueurActivity.this, Trie.class);
    			   intent.putExtra("myarray",myList);
    			               startActivity(intent);
     
    		default:
    			return super.onOptionsItemSelected(item);
    		}
     
    	}
     
     
    	@Override
    	protected boolean isRouteDisplayed() {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
     
     
     
    	@Override
    	public void onLocationChanged(Location location) {
    		lat = location.getLatitude();
    		lng = location.getLongitude();
     
    		Toast.makeText(
    			getBaseContext(),"Location change to : Latitude = " + lat + " Longitude = "
    				+ lng, Toast.LENGTH_LONG).show();
     
     
     
     
     
    		GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    		mc.animateTo(p);
    		mc.setCenter(p);
    		  Intent intent = getIntent();
    		  if (intent != null)
    		  { 
    			  String text=intent.getStringExtra(EXTRA_SUJET_RECHERCHE);
    			  Drawable drawable = this.getResources().getDrawable(R.drawable.marqueur1);
    				final ListItimizedOverlay itemizedoverlay = new ListItimizedOverlay(drawable,this);
    				final  String url ="https://maps.googleapis.com/maps/api/place/textsearch/json?query="+text+"&key=AIzaSyDxms7wMJorpD9LZVRL9OiozgV1D9wJKxo&sensor=true&location="+lat+","+lng+"&radius=500";
     
    				new AsyncTask<Void, Void, JSONObject>(){
    					@Override
    				protected JSONObject doInBackground(Void... params) {
    						// instancier la classe JsonParser
    						JsonParser jParser = new JsonParser ();
    						// récupérer le JSONObject à partir de l’url du fichier employes.json
    						JSONObject json = jParser.getJSONFromUrl(url);
     
    						return json;
    					};
     
     
    				protected void onPostExecute(JSONObject json) {
     
    					try {
     
    						// récupérer la liste de tous les employés
    						JSONArray results = json.getJSONArray(TAG_results);
    						int j=results.length();
    						 myList = new Place[j];
     
     
    						// parcourir toute la liste des employés
    						for(int i = 0; i < results.length(); i++){
     
    						// récupérer un employé de type JSONObject
    						JSONObject emp = results.getJSONObject(i);
     
    						// récupérer le JSONObject phone qui contient deux items
    						JSONObject geometry = emp.getJSONObject(TAG_geometry);
    						JSONObject location = geometry.getJSONObject(TAG_location);
    						String latitude = location.getString(TAG_lat);
    						String longitude= location.getString(TAG_lng);
    						double b = Double.parseDouble(latitude);
    						double c = Double.parseDouble(longitude);
    						String nom= emp.getString(TAG_name);
    						String adresse=emp.getString(TAG_adresse);
    						String reference =emp.getString(TAG_reference);
    						myList[i]=new Place(reference,nom,adresse,b,c,0);
     
    					GeoPoint geoPoint = new GeoPoint((int) (b* 1E6) , (int)(c* 1E6));
    					OverlayItem overlayitem = new OverlayItem(geoPoint, nom, adresse);
    					itemizedoverlay.addOverlayItem(overlayitem);
     
     
    					List<Overlay> mapOverlays = mapView.getOverlays();
    					mapOverlays.add(itemizedoverlay);
     
    					}
    					}
    					catch(JSONException e)
    					{
    						e.printStackTrace();
    					}
    				};
     
    			}.execute();
    	}
    	}
    Trie.java:
    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
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    package com.example.projet_fin_etude;
     
     
     
     
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashMap;
     
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.app.ListActivity;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
     
    public class Trie  extends ListActivity {
    	Place [] myList;
    	private static final String TAG_rows = "rows";
    	private static final String TAG_elements = "elements";
    	private static final String TAG_distance= "distance";
    	private static final String TAG_value= "value";
    	String url;
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.listplaceholder);
    		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    		Intent intent = getIntent();
    		Bundle extras =intent.getExtras();
    		if (extras != null){
    			this.myList = (Place[]) extras.getParcelableArray("myList");
    			 url="http://maps.googleapis.com/maps/api/distancematrix/json?origins="+myList[0].getLatitude()+","+myList[0].getLongitude()+"|"+"&destinations=";
    			for(int i=1;i<myList.length;i++)
    			{
    			url=url+myList[i].getLatitude()+","+myList[i].getLongitude()+"|";	
    			}
    			url=url+"&mode=walking&language=fr-FR&sensor=true";
    			new AsyncTask<Void, Void, JSONObject>(){
    				@Override
    				protected JSONObject doInBackground(Void... params) {
    						// instancier la classe JsonParser
    						JsonParser jParser = new JsonParser ();
    						// récupérer le JSONObject à partir de l’url du fichier employes.json
    						JSONObject json = jParser.getJSONFromUrl(url);
     
    						return json;
    					};
     
    					protected void onPostExecute(JSONObject json) {
     
    						try {
     
    							// récupérer la liste de tous les employés
    							JSONArray results = json.getJSONArray(TAG_rows);
     
     
     
     
    							// parcourir toute la liste des employés
    							for(int i = 0; i < results.length(); i++){
     
    							// récupérer un employé de type JSONObject
    							JSONObject emp = results.getJSONObject(i);
     
    							// récupérer le JSONObject phone qui contient deux items
    							JSONObject elements = emp.getJSONObject(TAG_elements);
    							JSONObject dist = elements.getJSONObject(TAG_distance);
    							String value = dist.getString(TAG_value);
    							int val_dist=Integer.parseInt(value);
    							myList[i].setDistance(val_dist);
    			}
    						}
    						catch(JSONException e)
    						{
    							e.printStackTrace();
    						}
    					};
     
    				}.execute();
    			}
    		Arrays.sort(myList);
    		for(int i=0;i<myList.length;i++)
    		{
    			HashMap<String, String> map = new HashMap<String, String>();
    			map.put("id",  String.valueOf(i));
    			map.put("name",myList[i].getNom());
    			map.put("adresse", myList[i].getAdresse());
    			list.add(map);
    		}
    		  ListAdapter adapter = new SimpleAdapter(this, list , R.layout.activity_trie, 
                      new String[] { "name", "adresse" }, 
                      new int[] { R.id.item_title, R.id.item_subtitle });
     
      setListAdapter(adapter);
      final ListView lv = getListView();
      lv.setTextFilterEnabled(true);	
      lv.setOnItemClickListener(new OnItemClickListener() {
      	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {        		
      		@SuppressWarnings("unchecked")
    			HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);	        		
      		Toast.makeText(Trie.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show(); 
     
    		}
    	});
    		}
     
     
     
     
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.activity_trie, menu);
    		return true;
    	}
     
    }
    Le logcat:

    04-17 14:43:40.418: D/AndroidRuntime(1138): Shutting down VM
    04-17 14:43:40.438: W/dalvikvm(1138): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
    04-17 14:43:40.508: E/AndroidRuntime(1138): FATAL EXCEPTION: main
    04-17 14:43:40.508: E/AndroidRuntime(1138): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.projet_fin_etude/com.example.projet_fin_etude.Trie}: java.lang.NullPointerException
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread.access$600(ActivityThread.java:141)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.os.Looper.loop(Looper.java:137)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread.main(ActivityThread.java:5041)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at java.lang.reflect.Method.invokeNative(Native Method)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at java.lang.reflect.Method.invoke(Method.java:511)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at dalvik.system.NativeStart.main(Native Method)
    04-17 14:43:40.508: E/AndroidRuntime(1138): Caused by: java.lang.NullPointerException
    04-17 14:43:40.508: E/AndroidRuntime(1138): at com.example.projet_fin_etude.Trie.onCreate(Trie.java:44)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.Activity.performCreate(Activity.java:5104)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    04-17 14:43:40.508: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    04-17 14:43:40.508: E/AndroidRuntime(1138): ... 11 more

  4. #24
    Membre actif
    Inscrit en
    Décembre 2008
    Messages
    280
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 280
    Points : 261
    Points
    261
    Par défaut
    Ben maintenant c'est jsute une histoire de liste vide, donc tu ne dois pas bien récupérer ton JSON dans marqueur ! vérifie que les donnée son correct avant de créer tes Place !
    Paye Tes Dettes - Applciation android.

    DevHackSecure - Pense bête d'un étudiant en informatique - Tutos DEV

    " I also realize that _everybody_ thinks that they are right, and that they are supported by all other right-thinking people. That's just how people work. We all think we're better than average." Linus Torvalds

  5. #25
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Merci pour tous vos aide.
    J'ai changée mon travail avec un ArrayList au lieu du tableau et ça marche bien.

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Erreur "FATAL EXCEPTION: main"
    Par bza88 dans le forum Android
    Réponses: 1
    Dernier message: 06/06/2013, 02h28
  2. FATAL EXCEPTION: main android
    Par nhmidi dans le forum Android
    Réponses: 1
    Dernier message: 25/02/2013, 11h22

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