Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème Application crash

Sujet résolu
    13 juin 2020 à 12:16:21

    Bonjour, 

    je rencontre un crash avec mon application quand j'appelle une fonction et je ne sais pas pourquoi... La fonction fait appelle à un script php qui marche hors de l'application mais je n'arrive pas à le faire marcher avec android studio j'ai l'impression :c

    Voici la fonction qui fait crash l'application. Elle ne fait ni l'action onSucces, ni l'action outErrors + son appel :

        public void getJSON(String Id_projet){
            request2.getJSONprojet(Id_projet, new RequestProjet.ProjetCallback() {
                @Override
                public void onSucces() {
                    Log.d("APP","Test final");
                    JSON = request2.getJSON();
                }
                @Override
                public void outErrors() {
                    Log.d("APP", "Error");
                }
            });
        }
        public void getIdProjet(){
            request2.getIdProjet(sessionManager.getId(), new RequestProjet.ProjetCallback() {
                @Override
                public void onSucces() {
                    Id_premier = request2.getNb_premier();
                    Id_deuxieme = request2.getNb_deuxieme();
                    Id_troisieme = request2.getNb_troisieme();
                    Log.d("APP", "Premier Id : "+ Id_premier );
                    Log.d("APP", "Premier Id : "+ Id_deuxieme );
                    Log.d("APP", "Premier Id : "+ Id_troisieme );
    
    
                    if(Id_premier != 0) {
                        Log.d("APP", "Premier Id envoyé : "+ Id_premier );
                        // Tout marche jusque là...
                        getJSON(String.valueOf(Id_premier));
                        Log.d("APP", "Texte obtenue : " + JSON.replaceAll("\\*", "\""));
                        Projet1 = Projet1.convertStringToProjet(JSON.replaceAll("\\*", "\""));
                    }
                }
                @Override
                public void outErrors() {
                    Log.d("APP", "Error");
                }
            });
        }

    Voici la requête. Lors de l'appelle de la fonction, la requête arrive jusqu'à test2 puis il y a un crash de l'application :

        public void getJSONprojet(final String Id_projet, final RequestProjet.ProjetCallback callback){
    
            String url = "http://MON_IP/espace_membre/getJSONprojet.php";
            Log.d("APP","test 1");
    
            StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d("APP","test 3");
                    try {
                        JSONObject json = new JSONObject(response);
                        Boolean error = json.getBoolean("error");
    
                        if(error){
                            // Erreur
                            Log.d("APP", "Erreur php");
                            callback.outErrors();
                        }
                        else{
                            JSON = json.getString("JSON");
                            callback.onSucces();
                        }
                    }
                    catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // Erreur
                    Log.d("APP", "Erreur interne");
                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
    
                    Map<String, String> map = new HashMap<>();
                    map.put("Id_projet", Id_projet); //en php $_POST['Id_projet'];
                    Log.d("APP","test 2");
    
                    return map;
                }
            };
    
            queue.add(request);
        }
    
        public String getJSON(){
            return this.JSON;
        }

    Et voici le script php qui marche en dehors de l'application et que j'utilise pour la requête :

    <?php 
    
    	$servername = 'localhost';
       	$username = 'root';
    	
       	
    
    	try{
    		$db = new PDO("mysql:host=$servername;dbname=projet_e3",$username,"");
    	}
    	catch(PDOException $e){
          	echo "Erreur : " . $e->getMessage();
        }
    
        $results["error"] = false;
    	$results["JSON"] = "";
    
    	//$_POST['Id_projet'] = 107;
    
    	if(!empty($_POST)){
    		$id = $_POST['Id_projet'];
    
    		$requete = $db->prepare('SELECT Json_text FROM projet WHERE Id_projet = :id');
    		$requete->execute([':id' => $id]);
    
    		while ($donnees = $requete->fetch())
    		{
    			$results["JSON"] = $donnees["Json_text"];
    		}
    	}
    	else{
    		$results["error"] = true;
    	}
    
    	echo json_encode($results);
    
    ?>

    Voyez vous d'où viens le problème ?

    Avant le crash j'obtient une erreur sur Logcat : 

    Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0



    -
    Edité par PierreChalandon 13 juin 2020 à 12:25:07

    • Partager sur Facebook
    • Partager sur Twitter
      13 juin 2020 à 12:24:41

      Salut,

      si ton application crash elle produit une stacktrace qui explique le problème. Sans la lire c’est impossible à dire.

      • Partager sur Facebook
      • Partager sur Twitter
        13 juin 2020 à 12:25:49

        Où ce trouve cette stacktrace ?

        EDIT: 

        E/AndroidRuntime: FATAL EXCEPTION: main

            Process: com.example.projete3_v2, PID: 9089

            java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.replaceAll(java.lang.String, java.lang.String)' on a null object reference

                at com.example.projete3_v2.AccueilActivity$11.onSucces(AccueilActivity.java:411)

        411 correspond ) la ligne où j'appelle ma fonction qui crash

        EDIT 2: 

        Hmm je viens de comprend d'où viens mon erreur ! Merci du tips pour la stacktrace

        -
        Edité par PierreChalandon 13 juin 2020 à 12:34:05

        • Partager sur Facebook
        • Partager sur Twitter

        Problème Application crash

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown