"D/Error.Response: com.android.Volley.Parseerror: com.google.gson.Jsonsyntaxexception: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $"

Asked

Viewed 70 times

-3

I have a listview that shows establishments in the database. Until today, in the morning, it was displayed and now no more and this error/ warning appears on the console

D/Error.Response: com.android.Volley.Parseerror: com.google.gson.Jsonsyntaxexception: java.lang.Illegalstateexception: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path path $

What does that mean?

Follows the code:

private void getAgenda(int idusuario) {

    int opcao = 3; //mostrar agenda do cliente
    final ArrayList<ConsultarPojo> agendaCliente = new ArrayList<>();
    RequestQueue queue = Volley.newRequestQueue(this);
    GsonRequest<ConsultarPojo[]> request = new GsonRequest<>("http://reservacomdomanda.com/areaAdmin/api/admin_estabelecimento/reqScheduleProJson.php?" +
            "idcliente="+idusuario+"&opcao="+opcao, ConsultarPojo[].class, null, new Response.Listener<ConsultarPojo[]>() {

        @Override
        public void onResponse(final ConsultarPojo[] response) {
            //Log.d("TAG", "Retorno... " + response.toString());
            for (int i = 0; i < response.length; i++) {
                ConsultarPojo agc = new ConsultarPojo();
                agc.idagendamentoProfissional = response[i].idagendamentoProfissional;
                agc.estabelecimento = response[i].estabelecimento;
                agc.unidade = response[i].unidade;
                agc.dia = response[i].dia;
                agc.hora = response[i].hora;
                agc.nome = response[i].nome;
                agc.funcao = response[i].funcao;
                agendaCliente.add(agc);
            }

            ArrayAdapter<ConsultarPojo> adapter = new ArrayAdapter<ConsultarPojo>(ConsultarActivity.this, android.R.layout.simple_list_item_1, agendaCliente);
            lvReservas = ((ListView)findViewById(R.id.lvReservas));
            lvReservas.setAdapter(adapter);
            lvReservas.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    //Log.d("Mensagem", "Id "+response[i].idagendamentoProfissional);
                    String idagendamento = response[i].idagendamentoProfissional;

                    Intent intentDetalhesAgendamento = new Intent(ConsultarActivity.this, DetalhesAgendamentoActivity.class);
                    intentDetalhesAgendamento.putExtra("idagendamento", idagendamento);
                    startActivity(intentDetalhesAgendamento);
                }
            });


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("Error.Response", String.valueOf(error));
        }
    });
    queue.add(request);
}

1 answer

0


This is happening because JSON is malformed, so I opened the URL http://reservacomdomanda.com/areaAdmin/api/admin_estabelecimento/reqScheduleProJson.php and soon noticed the problem

Parse error: syntax error, Unexpected 'default' (T_DEFAULT) in reqScheduleProJson.php on line 191

Not generating a JSON, it is error in your PHP, solving the problem will probably solve the rest.

You probably wrote something like:

switch (...) {
  case ...:
    ...
  case default:
    ...

When the right thing should be:

switch (...) {
  case ...:
    ...
  default:
    ...
  • 1

    I found the problem. My api was wrong.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.