Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseError post message #579

Open
eduardofp90 opened this issue Jan 25, 2022 · 1 comment
Open

parseError post message #579

eduardofp90 opened this issue Jan 25, 2022 · 1 comment

Comments

@eduardofp90
Copy link

I have this code and I have always the same error "onError errorDetail : parseError". I have tried to send a simple JSON but it doesn't work. What could be the problem the problem in the code?

btn_ok_mois.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
//POST JSON MOIS
JSONObject jsonObjectMOIS = new JSONObject();
try {
String valueMinMois = et_min_mois.getText().toString();
int finalvalueMinMois = Integer.parseInt(valueMinMois);
jsonObjectMOIS.put("minMois", finalvalueMinMois);
String valueMaxMois = et_max_mois.getText().toString();
int finalvalueMaxMois = Integer.parseInt(valueMaxMois);
jsonObjectMOIS.put("maxMois", finalvalueMaxMois);

            } catch (JSONException e) {
                e.printStackTrace();
            }
            AndroidNetworking.initialize(getApplicationContext());

            AndroidNetworking.post("https://example.com")
                    .addJSONObjectBody(jsonObjectMOIS ) // posting json
                    .setTag("moisture")
                    .setPriority(Priority.MEDIUM)
                    .build()
                    .getAsJSONObject(new JSONObjectRequestListener() {
                        @Override
                        public void onResponse(JSONObject response) {
                            // do anything with response
                            Toast.makeText(Thresholds.this,"OK",Toast.LENGTH_SHORT).show();
                            //tv_test.setText(response.toString());
                        }
                        @Override
                        public void onError(ANError error) {
                            // handle error
                            Toast.makeText(Thresholds.this,"ERROR",Toast.LENGTH_SHORT).show();
                            if (error.getErrorCode() != 0) {
                                Log.d(TAG, "onError errorCode : " + error.getErrorCode());
                                Log.d(TAG, "onError errorBody : " + error.getErrorBody());
                                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());

                            } else {
                                // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
                            }
                        }
                    });
        }
    });
@eduardofp90
Copy link
Author

I have to say that for some reason, the server gets the json but in my application I have the error: "onError errorDetail : parseError".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant