Jump to content

JSONException: No value for message


gmc1103

Recommended Posts

Hi again

 

Another issue.

This is my php code

if ($tag == 'reqSalasCheck') {
        $sala = filter_input(INPUT_POST, 'sala');
        $inicio = filter_input(INPUT_POST, 'inicio');
        $fim = filter_input(INPUT_POST, 'fim');
        $data = filter_input(INPUT_POST, 'dataFinal');
        $dias = strftime('%A', strtotime($data));
        $newDate = date("Y-m-d", strtotime($data));
        $diaId = mysql_query("SELECT * FROM `ebspma_paad_ebspma`.`semana_dias` WHERE dia ='$dias'");
        $diaRow = mysql_fetch_row($diaId)or die(mysql_error());
        $Dias = $diaRow[0];
        if ($Dias != null) {
            $inicioId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `inicio`='$inicio'");
            $inicioRow = mysql_fetch_row($inicioId)or die(mysql_error());
            $inicio = $inicioRow[0];
            if ($inicio != null) {
                $salaId = mysql_query("SELECT `idsala` FROM `ebspma_paad_ebspma`.`req_material_sala` WHERE `sala` = '$sala'");
                $salaRow = mysql_fetch_row($salaId)or die(mysql_error());
                $sala = $salaRow[0];
                if ($sala != null) {
                    $fimId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `fim`= '$fim'");
                    $fimRow = mysql_fetch_row($fimId)or die(mysql_error());
                    if ($fim != null) {
                        $checkIfOcupado = mysql_query("SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = '$Dias' AND id_sala= '$sala' AND id_tempo = '$inicio'");
                        $checkResult = mysql_fetch_row($checkIfOcupado) or die($checkIfOcupado . "<br/><br/>" . mysql_error());
                        $checkResultado = $checkResult[0];
                        if ($checkResultado > 0) {
                            $response["error"] = 2;
                            $response["error_msg"] = "Hora marcada no ano";
                            echo json_encode($response);
                        } else {
                            $checkIfReservado = mysql_query("SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` 
                            WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = '$sala'
                            AND (((`req_material_reserva`.`idtempoInicio` BETWEEN '$inicio' AND '$fim') AND (`req_material_reserva`.`idTempoFim` BETWEEN '$inicio' AND '$fim'))
                            OR (`req_material_reserva`.`idtempoInicio` <= '$inicio' AND `req_material_reserva`.`idTempoFim` >= '$fim'))
                            AND `req_material_reserva`.`data` = '$newDate'");
                            $checkReserva = mysql_fetch_row($checkIfReservado) or die($checkIfReservado . "<br/><br/>" . mysql_error());
                            $checkReservado = $checkReserva[0];
                            if ($checkReservado > 0) {
                                $response["error"] = 2;
                                $response["error_msg"] = "Oops! Sala reservada";
                                echo json_encode($response);
                            } else {
                                $response["success"] = 1;
                                $response["message"] = "Sala disponível.";
                                echo json_encode($response);
                            }
                        }
                    }
                }
            }
        }
    }

And  have this error in my android

Error parsing data org.json.JSONException: End of input at character 0 of

org.json.JSONException: No value for message

 

And my android is calling this json

private static final String KEY_MESSAGE = "message";
    private static final String KEY_MESSAGE_ERROR = "error_msg";     
	JSONObject salasCheck = userFunctions.reqSalasCheck(sala, inicio, fim, dataReserva);
            try {
                String res = salasCheck.getString(KEY_SUCCESS);
                Log.d("Mensagem", res);
                String error = salasCheck.getString(KEY_ERROR);
                Log.d("Mensagem", error);
                if (Integer.parseInt(res) == 1) {
                    String messageOK = salasCheck.getString(KEY_MESSAGE);

So why do i have this error in my php??

 

Link to comment
Share on other sites

Hi

 

I don't get what's wrong in this code...everything is so strange.

I'm passing the variables to php from this code

@SuppressLint("SimpleDateFormat")
    public JSONObject reqSalasCheck(String sala, String inicio, String fim, Date dataReserva) {
        // Parametros a passar para php
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String dataFinal = String.valueOf(dataReserva);
        String reqSalasCheck_tag = "reqSalasCheck";
        params.add(new BasicNameValuePair("tag", reqSalasCheck_tag));
        params.add(new BasicNameValuePair("sala", sala));
        params.add(new BasicNameValuePair("inicio", inicio));
        params.add(new BasicNameValuePair("fim", fim));
        params.add(new BasicNameValuePair("dataFinal", dataFinal));
        JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
        return json;
    }

and the debuger gives me this error

 

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.http.message.BasicNameValuePair.toString()

 

in every variable 

Link to comment
Share on other sites

  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.