What is this error "D/TAG: Return...: [Lcom.example.Gustavo.domanda.Consultarpojo;@11c78941"

Asked

Viewed 21 times

0

I have the following code that should return a data list

package com.example.gustavo.domanda;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;

import java.util.ArrayList;

public class ConsultarActivity extends AppCompatActivity {

private ListView lvReservas;

private int idusuario;
private String nome;
private String sobrenome;
private RequestQueue mVolleyRequest;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_consultar);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Bundle extra = getIntent().getExtras();

    if(extra != null){
        idusuario = extra.getInt("idusuario");
        nome = extra.getString("nome");
        sobrenome = extra.getString("sobrenome");
    }

    getAgenda(idusuario);

}

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(ConsultarPojo[] response) {
            Log.d("TAG", "Retorno... " + response);
            for (int i = 0; i < response.length; i++) {
                ConsultarPojo agc = new ConsultarPojo();
                agc.dia = response[i].dia;
                agc.hora = response[i].hora;
                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);
            adapter.notifyDataSetChanged();

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

}

And on the line where I wrote "TAG", "Return... " + Sponse, on the console appears

D/TAG: Return... [Lcom.example.Gustavo.domanda.Consultarpojo;@f6cde00

What mistake or problem is this?

2 answers

1

This is not an error, it is the string that represents the object.

When you use an object of this form, implicit conversion to string, the return of the method is used toString() of that object.

The standard implementation of the method toString() returns a string consisting of the class name, of which the object is an instance, the character @ and the hexadecimal representation of the object hash code, the equivalent of

getClass().getName() + '@' + Integer.toHexString(hashCode());
  • And what should I do to show the data of the object? I already put Sponse.toString() but it did not help

  • @Gustavosevero, you asked a question and it was answered. If that’s not what you wanted to ask, ask another question.

  • "TAG", "Retorno... " + response is equal to "TAG", "Retorno... " + response.toString()

  • Putting Sponse.toString() did not help, unfortunately

  • I didn’t tell you to put response.toString(). On the contrary, you said it was the same. You asked, in relation to what appeared in the log, "What mistake or problem is this?" that’s what I answered to.

  • All right, thanks for your help.

Show 1 more comment

0

You are trying to concatenate a direct string ("Return...") into the log with an Object Array (Sponse). It’s no mistake, it just took the "header" that describes the Array. If you want to take a specific item from the Array, use the indexers, and as is Object Array of a class of yours, you have to call the getter or the variable you want to display from the object.

Ex: By your code, I saw that your class ConsultarPojo has a variable dia, then it would look something like this:

Log.d("TAG", "Retorno... " + response[0].dia);
  • Sorry, what "header" are you talking about? And I actually want to fetch all the data from the array... I want to see what’s coming

  • It has day and hour... Both must appear kkkk

  • I’m talking about an internal header that the code generates after compiled. After all, the Array is not a String. Concatenations only work between Strings. If you want to take all the values of the Array, make a loop that concatenates all the data of the same

  • I just gave an example of something "concatenable" in your code. Use the class variables and members of the Array you want from there.

  • But there’s already a FOR to get the data I want

Browser other questions tagged

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