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 :

NullpointerException dans l'activity


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2011
    Messages : 13
    Points : 11
    Points
    11
    Par défaut NullpointerException dans l'activity
    bonjour,

    Il y'a quelque temps je commence à m'intéresser a la programmation Android et je vous m’entraîner en créant une application qui nécessite une authentification ,j'ai trouvé se super tuto http://www.androidhive.info/2012/05/...ith-php-mysql/ et j'aimerai l'appliquer mais j'ai eu un probleme de compilation que j'ai du mal a en detecter la source.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    11-23 17:36:18.964: E/AndroidRuntime(2265): FATAL EXCEPTION: main
    11-23 17:36:18.964: E/AndroidRuntime(2265): java.lang.NullPointerException
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at com.ta3alam.activity.MainActivity$GetUser$1.run(MainActivity.java:126)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at android.os.Handler.handleCallback(Handler.java:615)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at android.os.Looper.loop(Looper.java:137)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at java.lang.reflect.Method.invokeNative(Native Method)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at java.lang.reflect.Method.invoke(Method.java:511)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-23 17:36:18.964: E/AndroidRuntime(2265): 	at dalvik.system.NativeStart.main(Native Method)
    voila l'activité en question :
    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
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    package com.ta3alam.activity;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
     
    public class MainActivity extends Activity {
     
     
    	ProgressDialog pDialog;
    	JSONParser jsonParser;
    	String login ="par Defaut";	
    	String password ="par defaut";
     
    	String loginSaisi;	
    	String passwordSaisi;
     
    	EditText inputLogin = null;
    	EditText inputPassword = null;
    	Button btnConnexion = null;
    	Button btnInscription = null;
     
     
    	 // url to create new product
        private static String url_get_user_details = "http://192.168.1.8/ta3alam_conectitivty/get_user_details.php";
        private static final String TAG_SUCCESS = "success";
        private static final String TAG_USER = "utilisateur";
        private static final String TAG_LOGIN="login";
        private static final String TAG_PASSWORD="password";
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.authentification);
     
            inputLogin =(EditText)findViewById(R.id.editTextLogin);
     
     
            inputPassword =(EditText)findViewById(R.id.editTextPassword);
     
     
            btnConnexion = (Button)findViewById(R.id.buttonConnection);
            btnConnexion.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {
     
     
    				new GetUser().execute();
     
     
     
     
    			}
    		});
     
            btnInscription =(Button)findViewById(R.id.btnInscription);
     
            btnInscription.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {				
    				Intent i = new Intent(getApplicationContext(),NewUserActivity.class);				
    				startActivity(i);				
    			}
    		});
     
     
        }
     
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
     
        class GetUser extends AsyncTask<String, String, String> {
     
            /**
             * Before starting background thread Show Progress Dialog
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Loading product details. Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();
            }
     
            /**
             * Getting product details in background thread
             * */
            protected String doInBackground(String... params) {
     
                // updating UI from Background Thread
                runOnUiThread(new Runnable() {
                    public void run() {
                        // Check for success tag
                        int success;
                        try {
                        	loginSaisi = inputLogin.getText().toString();
                        	passwordSaisi = inputPassword.getText().toString();
     
                            // Building Parameters
                            List<NameValuePair> params = new ArrayList<NameValuePair>();
                            params.add(new BasicNameValuePair("login", loginSaisi));
     
                            // getting product details by making HTTP request
                            // Note that product details url will use GET request
    //
                            JSONObject json = jsonParser.makeHttpRequest(
                            		url_get_user_details, "GET", params);//le debogage bloque ici
     
                            // check your log for json response
                            Log.d("Single Product Details", json.toString());
     
                            // json success tag
                            success = json.getInt(TAG_SUCCESS);
                            if (success == 1) {
                                // successfully received product details
                                JSONArray productObj = json
                                        .getJSONArray(TAG_USER); // JSON Array
     
                                // get first product object from JSON Array
                                JSONObject user = productObj.getJSONObject(0);
     
                               login = user.getString(TAG_LOGIN);
                               password = user.getString(TAG_PASSWORD);
     
                               if(testAuthentification(login, password, loginSaisi, passwordSaisi))
                               {
                            	   Intent i = new Intent(getApplicationContext(),Bienvenu.class);
                            	   startActivity(i);
                               }
     
     
     
                            }else{
                                // product with pid not found
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
     
                return null;
            }
     
            /**
             * After completing background task Dismiss the progress dialog
             * **/
            protected void onPostExecute(String file_url) {
                // dismiss the dialog once got all details
                pDialog.dismiss();
            }
        }
     
        private boolean testAuthentification(final String login1 ,final String password1,final String login2,final String password2)
        {
        	if(login1.equals(login2) && password1.equals(password2))
        	{
        		return true;
        	}else
        	{
        		return false;
        	}
     
        }
    }
    dans cette activité je veux juste premettre a l'utilisateur de saisir un login et un mots de passe et les comparer avec le login et le mots de passe dans la base de donnée

    le deboguage bloque dans cette ligne JSONObject json = jsonParser.makeHttpRequest(
    url_get_user_details, "GET", params);//le debogage bloque ici

    j'ai testé le code php il marche mais je le poste quand meme juste pour vous mettre dans le contexte
    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
    <?php
     
    /*
     * Following code will get single product details
     * A product is identified by product id (pid)
     */
     
    // array for JSON response
    $response = array();
     
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
     
    // connecting to db
    $db = new DB_CONNECT();
     
    // check for post data
    if (isset($_GET["login"])) {
        $login = $_GET['login'];
     
        // get a product from products table
        $result = mysql_query("SELECT *FROM utilisateur WHERE login = '$login'");
     
        if (!empty($result)) {
            // check for empty result
            if (mysql_num_rows($result) > 0) {
     
                $result = mysql_fetch_array($result);
     
                $utilisateur = array();
                $utilisateur["id_utlisateur"] = $result["id_utlisateur"];
                $utilisateur["prenom"] = $result["prenom"];
                $utilisateur["profession"] = $result["profession"];
                $utilisateur["adress"] = $result["adress"];
                $utilisateur["tel"] = $result["tel"];
                $utilisateur["email"] = $result["email"];
    			$utilisateur["login"] = $result["login"];
    			$utilisateur["password"] = $result["password"];
    			$utilisateur["role"] = $result["role"];
                // success
                $response["success"] = 1;
     
                // user node
                $response["utilisateur"] = array();
     
                array_push($response["utilisateur"], $utilisateur);
     
                // echoing JSON response
                echo json_encode($response);
            } else {
                // no product found
                $response["success"] = 0;
                $response["message"] = "No product found 1";
     
                // echo no users JSON
                echo json_encode($response);
            }
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found 2";
     
            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // required field is missing
        $response["success"] = 0;
        $response["message"] = "Required field(s) is missing";
     
        // echoing JSON response
        echo json_encode($response);
    }
    ?>

  2. #2
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    si tu utilise Eclipse il y'a ce que en appel le débogage

  3. #3
    Membre à l'essai
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2011
    Messages : 13
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par azstar Voir le message
    si tu utilise Eclipse il y'a ce que en appel le débogage
    tout d'abord merci pour votre intérêt pour le sujet ,

    oui j'utilise éclipse et oui j'ai utilisé le débogage avant de poster ce sujet et je ne pense pas qu'il y'a un IDE qui n'a pas d'option de débogage

    en faites j'ai enlevé le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    // updating UI from Background Thread
    runOnUiThread(new Runnable() {
    public void run() {
    // Check for success tag
    ma classe est devenu
    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
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
     
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
     
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
     
    public class MainActivity extends Activity {
     
     
    	ProgressDialog pDialog;
    	JSONParser JParser;
    	String login ="par Defaut";	
    	String password ="par defaut";
     
    	String loginSaisi;	
    	String passwordSaisi;
     
    	EditText inputLogin = null;
    	EditText inputPassword = null;
    	Button btnConnexion = null;
    	Button btnInscription = null;
     
    	// products JSONArray
        JSONArray users = null;
     
     
    	 // url to create new product
        private static String url_get_user_details = "http://192.168.137.3/ta3alam_conectitivty/get_user_details.php";
        private static final String TAG_SUCCESS = "success";
        private static final String TAG_USER = "utilisateur";
        private static final String TAG_LOGIN="login";
        private static final String TAG_PASSWORD="password";
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.authentification);
     
            inputLogin =(EditText)findViewById(R.id.editTextLogin);
     
     
            inputPassword =(EditText)findViewById(R.id.editTextPassword);
     
     
            btnConnexion = (Button)findViewById(R.id.buttonConnection);
            btnConnexion.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {
     
     
    				new GetUser().execute();
     
     
     
     
    			}
    		});
     
            btnInscription =(Button)findViewById(R.id.btnInscription);
     
            btnInscription.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {				
    				Intent i = new Intent(getApplicationContext(),NewUserActivity.class);				
    				startActivity(i);				
    			}
    		});
     
     
        }
     
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
     
        class GetUser extends AsyncTask<String, String, String> {
     
            /**
             * Before starting background thread Show Progress Dialog
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Loading product details. Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();
            }
     
            /**
             * Getting product details in background thread
             * */
            protected String doInBackground(String... arg0) {
     
            	loginSaisi = inputLogin.getText().toString();
            	passwordSaisi = inputPassword.getText().toString();
     
     
            	 // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("login", loginSaisi));
     
                // getting JSON string from URL
                JSONObject json = JParser.makeHttpRequest(url_get_user_details, "GET", params);
     
     
             // Check your log cat for JSON reponse
                Log.d("All Products: ", json.toString());
     
                try {
     
                	// Checking for SUCCESS TAG
                    int success = json.getInt(TAG_SUCCESS);
     
                    if(success == 1)
                    {
     
                    	// products found
                        // Getting Array of Products
                        users = json.getJSONArray(TAG_USER);
     
     
                        	JSONObject c = users.getJSONObject(0);
     
                        	// Storing each json item in variable
                        	password = c.getString(TAG_PASSWORD);
                            login = c.getString(TAG_LOGIN);
     
                        if(testAuthentification(login, password, loginSaisi, passwordSaisi))
                        {
                        	Intent i = new Intent(getApplicationContext(), Bienvenu.class);
                        	startActivity(i);
                        }
     
     
                        }
     
     
     
    			} catch (JSONException e) {
    				e.printStackTrace();
    			}
    			return null;
            }
     
            /**
             * After completing background task Dismiss the progress dialog
             * **/
            protected void onPostExecute(String file_url) {
                // dismiss the dialog once got all details
                pDialog.dismiss();
            }
        }
     
        private boolean testAuthentification(final String login1 ,final String password1,final String login2,final String password2)
        {
        	if(login1.equals(login2) && password1.equals(password2))
        	{
        		return true;
        	}else
        	{
        		return false;
        	}
     
        }
    }
    et du coup le message d'erreur a changé
    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
     
    11-23 20:12:24.942: E/WindowManager(1263): Activity com.ta3alam.activity.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41316160 that was originally added here
    11-23 20:12:24.942: E/WindowManager(1263): android.view.WindowLeaked: Activity com.ta3alam.activity.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41316160 that was originally added here
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.Window$LocalWindowManager.addView(Window.java:547)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.app.Dialog.show(Dialog.java:277)
    11-23 20:12:24.942: E/WindowManager(1263): 	at com.ta3alam.activity.MainActivity$GetUser.onPreExecute(MainActivity.java:107)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.os.AsyncTask.execute(AsyncTask.java:534)
    11-23 20:12:24.942: E/WindowManager(1263): 	at com.ta3alam.activity.MainActivity$1.onClick(MainActivity.java:68)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.View.performClick(View.java:4084)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.view.View$PerformClick.run(View.java:16966)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.os.Handler.handleCallback(Handler.java:615)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.os.Looper.loop(Looper.java:137)
    11-23 20:12:24.942: E/WindowManager(1263): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-23 20:12:24.942: E/WindowManager(1263): 	at java.lang.reflect.Method.invokeNative(Native Method)
    11-23 20:12:24.942: E/WindowManager(1263): 	at java.lang.reflect.Method.invoke(Method.java:511)
    11-23 20:12:24.942: E/WindowManager(1263): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-23 20:12:24.942: E/WindowManager(1263): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-23 20:12:24.942: E/WindowManager(1263): 	at dalvik.system.NativeStart.main(Native Method)
    le problème et que je n'ai fermé aucune activité

  4. #4
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    La première erreur (premier message) est simple:

    11-23 17:36:18.964: E/AndroidRuntime(2265): at com.ta3alam.activity.MainActivity$GetUser$1.run(MainActivity.java:126)

    La seule fonction correspondant est:
    JSONObject json = jsonParser.makeHttpRequest(

    Ce qui implique obligatoirement (sans debuguer) que jsonParser est null à ce moment là.


    La seconde:
    11-23 20:12:24.942: E/WindowManager(1263): at com.ta3alam.activity.MainActivity$GetUser.onPreExecute(MainActivity.java:107)

    Ce qui veut dire qu'au moment du pDialog.show(); (au passage, une question, c'est quoi ce 'p' ? Si c'est 'pour pointeur' on est en Java, il n'y a QUE des pointeurs ^^) une 'window' attachée à l'activité a dû être supprimée sans être fermée proprement... ce qui arrive notamment quand on essaye d'afficher deux boites de dialogue en même temps.

    Bon ensuite je ne rentrerait pas dans les commentaire de la tâche (ni même de la manière dont le pseudo-login est effectué), commençons par les problèmes 'urgents'
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  5. #5
    Membre à l'essai
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2011
    Messages : 13
    Points : 11
    Points
    11
    Par défaut
    Bonjour Nicroman et les moderateurs

    tous d'abord je suis desolé pour le titre du sujet et merci de l'avoir changer

    j'aimerai remercier Nicroman pour l'aide je croyais le problème ne venait que du Jsonparser voila que meme le pDialog est concerné (en fait le p c'est comme progress et non pointeur ca fait ProgressDialog ).Je ne comprend pas pourquoi le makeHttpRequest retourne null tous ses paramètre ne le sont pas au moment de l'appelle je l'ai utilisé dans d'autre activité et ca marche ,j'ai listé les login des utilisateurs et j'ai enregistré des utilisateurs et ca marche a merveille pourquoi la ca ne marche pas

    en fait voila le JSONParser :

    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
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.util.List;
     
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.client.utils.URLEncodedUtils;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.util.Log;
     
    public class JSONParser {
    	 static InputStream is = null;
    	    static JSONObject jObj = null;
    	    static String json = "";
     
    	    // constructor
    	    public JSONParser() {
     
    	    }
     
    	    // function get json from url
    	    // by making HTTP POST or GET mehtod
    	    public JSONObject makeHttpRequest(String url, String method,
    	            List<NameValuePair> params) {
     
    	        // Making HTTP request
    	        try {
     
    	            // check for request method
    	            if(method == "POST"){
    	                // request method is POST
    	                // defaultHttpClient
    	                DefaultHttpClient httpClient = new DefaultHttpClient();
    	                HttpPost httpPost = new HttpPost(url);
    	                httpPost.setEntity(new UrlEncodedFormEntity(params));
     
    	                HttpResponse httpResponse = httpClient.execute(httpPost);
    	                HttpEntity httpEntity = httpResponse.getEntity();
    	                is = httpEntity.getContent();
     
    	            }else if(method == "GET"){
    	                // request method is GET
    	                DefaultHttpClient httpClient = new DefaultHttpClient();
    	                String paramString = URLEncodedUtils.format(params, "utf-8");
    	                url += "?" + paramString;
    	                HttpGet httpGet = new HttpGet(url);
     
    	                HttpResponse httpResponse = httpClient.execute(httpGet);
    	                HttpEntity httpEntity = httpResponse.getEntity();
    	                is = httpEntity.getContent();
    	            }           
     
    	        } catch (UnsupportedEncodingException e) {
    	            e.printStackTrace();
    	        } catch (ClientProtocolException e) {
    	            e.printStackTrace();
    	        } catch (IOException e) {
    	            e.printStackTrace();
    	        }
     
    	        try {
    	            BufferedReader reader = new BufferedReader(new InputStreamReader(
    	                    is, "iso-8859-1"), 8);
    	            StringBuilder sb = new StringBuilder();
    	            String line = null;
    	            while ((line = reader.readLine()) != null) {
    	                sb.append(line + "\n");
    	            }
    	            is.close();
    	            json = sb.toString();
    	        } catch (Exception e) {
    	            Log.e("Buffer Error", "Error converting result " + e.toString());
    	        }
     
    	        // try parse the string to a JSON object
    	        try {
    	            jObj = new JSONObject(json);
    	        } catch (JSONException e) {
    	            Log.e("JSON Parser", "Error parsing data " + e.toString());
    	        }
     
    	        // return JSON String
    	        return jObj;
     
    	    }
    }

  6. #6
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Houuuu le parser me fait hérisser le poil !! ^^
    (voir les innombrables posts précédents au sujet des try/catch / printStackTrace... en résumé: un try/catch ne sert pas à faire disparaitre une erreur java....)

    Mais bon, en l’occurrence ce n'est pas makeHttpRequest qui renvoit null (il n'y aurait pas d'exception pour ca), mais la variable jsonParser qui ne contient RIEN (null, du coup, appeler une méthode [makeHttpRequest] d'un objet null => NullPointerException).
    Maintenant il s'appelle "JParser" (avec une majuscule ! attention c'est une variable => minuscule au début), mais je ne vois toujours aucune assignation (JParser = ....) donc la variable est toujours nulle....
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  7. #7
    Membre à l'essai
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2011
    Messages : 13
    Points : 11
    Points
    11
    Par défaut
    s'ayez c'est résolu fallait tout bêtement instancier le jParser avant d’appeler le makeHTTPRequest

    merci beaucoup nicroman et aztar

  8. #8
    Membre à l'essai
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2011
    Messages : 13
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par nicroman Voir le message
    Houuuu le parser me fait hérisser le poil !! ^^
    (voir les innombrables posts précédents au sujet des try/catch / printStackTrace... en résumé: un try/catch ne sert pas à faire disparaitre une erreur java....)

    Mais bon, en l’occurrence ce n'est pas makeHttpRequest qui renvoit null (il n'y aurait pas d'exception pour ca), mais la variable jsonParser qui ne contient RIEN (null, du coup, appeler une méthode [makeHttpRequest] d'un objet null => NullPointerException).
    Maintenant il s'appelle "JParser" (avec une majuscule ! attention c'est une variable => minuscule au début), mais je ne vois toujours aucune assignation (JParser = ....) donc la variable est toujours nulle....
    voila ,c'est l'objet jParser qui est null pas la methode makeHTTPRequest qui le retourne,pour le JParser j'etais tellement stressé que j'ai oublié les normes standrad de codage JAVA merci pour ta remarque

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

Discussions similaires

  1. Mettre une icone dans une activity
    Par arasium dans le forum SharePoint
    Réponses: 2
    Dernier message: 11/10/2007, 09h58
  2. Récupérer le logon post-Windows 2000 dans l'active directory
    Par Tuizi dans le forum VB 6 et antérieur
    Réponses: 0
    Dernier message: 11/09/2007, 11h50
  3. NullPointerException dans JBuilder
    Par baya1 dans le forum JBuilder
    Réponses: 2
    Dernier message: 19/04/2007, 19h53
  4. ldap_add() ajout utilisateur dans l'active directry
    Par toxyko dans le forum Langage
    Réponses: 3
    Dernier message: 03/07/2006, 23h23
  5. [POO] Créer un user dans une Active Directory (LDAP)
    Par Invité dans le forum Langage
    Réponses: 15
    Dernier message: 17/06/2006, 00h46

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