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 "End of input at character 0 of"


Sujet :

Android

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2015
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 56
    Points : 29
    Points
    29
    Par défaut Erreur "End of input at character 0 of"
    Bonjour,

    J'ai réalisé un code pour insérer des données dans un serveur distant depuis un client Android et j'ai bien réussi à insérer des données mais juste après, l'application se bloque et il m'affiche le message d'erreur suivant :
    End of input at character 0 of
    J'ai cherché sur le net mais je n'ai pas trouvé de solution qui convienne.

    Voici mon code de la classe 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
    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;
            }
        }
    Et voici la classe d'ajout dans la BDD
    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
    public class AjouterClient extends Activity {
        // Progress Dialog
        private ProgressDialog pDialog;
     
        JSONParser jsonParser = new JSONParser();
        EditText inputid;
        EditText inputnom;
        EditText inputprix;
        EditText inputdesc;
        Button  btnCreateProduct;
        // url  create  product
        private static String url_create_product = "http://192.168.1.16/createPRODUCT2.php";
     
        private static final String TAG_SUCCESS = "success";
     
        public void onCreate (Bundle savedInstanceState) {
     
            super.onCreate(savedInstanceState);
            setContentView(R.layout.ajouterclient);
     
                    // Edit Text
                     inputid = (EditText)  findViewById(R.id.btnid);
                    inputnom = (EditText) findViewById(R.id.btnnom);
                    inputprix = (EditText) findViewById(R.id.btnprix);
                    inputdesc = (EditText) findViewById(R.id.btndesc);
     
                     btnCreateProduct = (Button) findViewById(R.id.btnvalider);
     
                    btnCreateProduct.setOnClickListener(new View.OnClickListener() {
     
                        @Override
                        public void onClick(View view) {
     
                            new CreateNewProduct().execute();
                        }
                    });
                }
                class CreateNewProduct extends AsyncTask<String, String, String> {
                               @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        pDialog = new ProgressDialog(AjouterClient.this);
                        pDialog.setMessage("Creating Product..");
                        pDialog.setIndeterminate(false);
                        pDialog.setCancelable(true);
                        pDialog.show();
                    }
     
                    protected String doInBackground(String... args) {
     
                       String id = inputid.getText().toString();
                        String nom = inputnom.getText().toString();
                        String prix = inputprix.getText().toString();
                        String description = inputdesc.getText().toString();
     
                        //
                        List<NameValuePair> params = new ArrayList<NameValuePair>();
     
                        params.add(new BasicNameValuePair("PID", id));
                        params.add(new BasicNameValuePair("NAME", nom));
                        params.add(new BasicNameValuePair("PRICE",prix));
                        params.add(new BasicNameValuePair("DESCRIPTION", description));
     
                        //
                        //
                        JSONObject json = jsonParser.makeHttpRequest(url_create_product, "POST", params);
     
     
                        //
                        Log.d("Create Response", json.toString());
     
                        try {
                            int success = json.getInt(TAG_SUCCESS);
     
                            if (success == 1) {
                                // succes created product
                                Intent i = new Intent(getApplicationContext(), Afficher_listCL.class);
                                startActivity(i);
     
     
                                finish();
                            }
                        }
                            catch (JSONException e) {
                            e.printStackTrace();
                        }
     
                        return null;
                    }
     
                   protected void onPostExecute(String file_url) {
     
                        pDialog.dismiss();
                    }
                    }
                }
    Voici également le côté PHP
    Code php : 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
    <?php
     
      $dbName = 'localhost:D:/TEST.FDB';
      $dbUser = 'SYSDBA';
      $dbPswd = 'masterkey';
    // ouvrir la cox a une bdd 
       @($db = ibase_connect($dbName, $dbUser, $dbPswd)) or $db = nul;
    // array for JSON response
     
         $response = array();
     
    // check for required fields
    if ( isset($_POST['PID']) && isset($_POST['NAME']) && isset($_POST['PRICE']) && isset($_POST['DESCRIPTION'])) {
     
       $PID = $_POST['PID'];
        $NAME = $_POST['NAME'];
        $PRICE = $_POST['PRICE'];
        $DESCRIPTION = $_POST['DESCRIPTION'];
     
     
        // mysql inserting a new row
        $result = ibase_query("INSERT INTO PRODUCTS( PID, NAME, PRICE, DESCRIPTION) VALUES('$PID','$NAME', '$PRICE', '$DESCRIPTION')");
     
        // check if row inserted or not
        if ($result) {
            // successfully inserted into database
            $response["success"] = 1;
            $response["message"] = "Product successfully created.";
     
            // echoing JSON response
            //echo json_encode($response);
        } else {
            // failed to insert row
            $response["success"] = 0;
            $response["message"] = "Oops! An error occurred.";
     
            // echoing JSON response
           // 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);
    }
    ?>
    Mon logcat m'affiche ce qui suit :
    29:29.448 745-758/riro15.exemple_web_service E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 0 of
    03-20 11:29:29.558 745-758/riro15.exemple_web_service W/dalvikvm﹕ threadid=10: thread exiting with uncaught exception (group=0x40015560)
    03-20 11:29:30.208 745-758/riro15.exemple_web_service E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:200)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1019)
    Caused by: java.lang.NullPointerException
    at riro15.exemple_web_service.AjouterClient$CreateNewProduct.doInBackground(AjouterClient.java:92)
    at riro15.exemple_web_service.AjouterClient$CreateNewProduct.doInBackground(AjouterClient.java:60)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    ************at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    ************at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    ************at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    ************at java.lang.Thread.run(Thread.java:1019)
    03-20 11:29:36.587 745-745/riro15.exemple_web_service E/WindowManager﹕ Activity riro15.exemple_web_service.AjouterClient has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40538ac8 that was originally added here
    android.view.WindowLeaked: Activity riro15.exemple_web_service.AjouterClient has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40538ac8 that was originally added here
    at android.view.ViewRoot.<init>(ViewRoot.java:258)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
    at android.view.Window$LocalWindowManager.addView(Window.java:424)
    at android.app.Dialog.show(Dialog.java:241)
    at riro15.exemple_web_service.AjouterClient$CreateNewProduct.onPreExecute(AjouterClient.java:68)
    at android.os.AsyncTask.execute(AsyncTask.java:391)
    at riro15.exemple_web_service.AjouterClient$1.onClick(AjouterClient.java:56)
    at android.view.View.performClick(View.java:2485)
    at android.view.View$PerformClick.run(View.java:9080)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
    Quelqu'un saurait-il m'indiquer à résoudre ce problème ?

    Merci d'avance pour votre aide.

  2. #2
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2015
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 56
    Points : 29
    Points
    29
    Par défaut
    quelqu'un peut me dire s'il vous plait se message dans le logcat se qui veux dire :

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)

  3. #3
    Expert éminent sénior
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    3 020
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 3 020
    Points : 16 092
    Points
    16 092
    Par défaut
    Hello, à priori, c'est ton objet json qui est mal formé.

    Le message que tu nous demandes de t'expliquer n'est qu'un des élements de la stacktrace, en soi, il ne veut pas dire grand chose.

    Est-ce que tu as vérifié ce que tu envoyais dans la classe qui fait l'appel, et est-ce que tu as vérifié ce que tu recevais dans la classe qui reçoit l'appel?

  4. #4
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2015
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 56
    Points : 29
    Points
    29
    Par défaut
    mais comment puis-je vérifier l'envoi et la réception des données

  5. #5
    Expert éminent sénior
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    3 020
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 3 020
    Points : 16 092
    Points
    16 092
    Par défaut
    Tu peux ajouter du log dans ta classe JSONParser

    Moi je verrais bien que lorsque tu fais : jObj = new JSONObject(json); que ton objet json soit null ou vide.

    Sinon, tu peux aussi passer en debug dans ta classe. Au moins tu pourras voir toutes les valeurs de tous tes objets étape par étape.

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    pour ce que je vois de ton php, il n'envoie pas de json en réponse, donc tu a une JSonException coté android et comme tu ne catch pas cette exception, elle remonte avec ce message "uncaught exception".

    Dans ton php, toutes les lignes affichant un résultat sont commentées ....

  7. #7
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Points : 1 493
    Points
    1 493
    Par défaut
    Bonjour,

    Même remarque que @tchize_, tu as grisé les qui devraient renvoyer les résultats. Donc ton script php ne renvoie rien au client. Enlève les "//" devant les lignes où se trouve l'instruction "echo".

    Ton code va ressembler à ça :
    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
    <?php
     
      $dbName = 'localhost:D:/TEST.FDB';
      $dbUser = 'SYSDBA';
      $dbPswd = 'masterkey';
    // ouvrir la cox a une bdd 
       @($db = ibase_connect($dbName, $dbUser, $dbPswd)) or $db = nul;
    // array for JSON response
     
         $response = array();
     
    // check for required fields
    if ( isset($_POST['PID']) && isset($_POST['NAME']) && isset($_POST['PRICE']) && isset($_POST['DESCRIPTION'])) {
     
       $PID = $_POST['PID'];
        $NAME = $_POST['NAME'];
        $PRICE = $_POST['PRICE'];
        $DESCRIPTION = $_POST['DESCRIPTION'];
     
     
        // mysql inserting a new row
        $result = ibase_query("INSERT INTO PRODUCTS( PID, NAME, PRICE, DESCRIPTION) VALUES('$PID','$NAME', '$PRICE', '$DESCRIPTION')");
     
        // check if row inserted or not
        if ($result) {
            // successfully inserted into database
            $response["success"] = 1;
            $response["message"] = "Product successfully created.";
     
            // echoing JSON response
           echo json_encode($response);
        } else {
            // failed to insert row
            $response["success"] = 0;
            $response["message"] = "Oops! An error occurred.";
     
            // echoing JSON response
           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);
    }
    ?>
    Christian Djo
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

  8. #8
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2015
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 56
    Points : 29
    Points
    29
    Par défaut
    merciiii c régler c'est hyper gentil tous le monde

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

Discussions similaires

  1. [cellfun] Erreur "Too many inputs"
    Par syki.mail dans le forum MATLAB
    Réponses: 9
    Dernier message: 29/12/2011, 06h27
  2. [uicontrol] Erreur "Too many input arguments."
    Par oliv27400 dans le forum Interfaces Graphiques
    Réponses: 5
    Dernier message: 02/06/2010, 11h06
  3. [W3C] Erreur W3C sur "input"
    Par jlb59 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 23
    Dernier message: 13/03/2008, 09h23
  4. Erreur : end-of-file during read
    Par phy4me dans le forum Fortran
    Réponses: 3
    Dernier message: 09/05/2007, 19h59
  5. [JDBC] [Oracle] Erreur : End of TNS data channel
    Par loicmillion dans le forum JDBC
    Réponses: 2
    Dernier message: 01/02/2005, 14h27

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