我正在尝试调试我的应用程序,以查看它在哪里停止运行,但是我对以下日志“ Ljava.lang.StackTraceElement; @ 42088f90”感到困惑,我不知道它的含义或含义。
07-01 13:55:30.957 11534-11534/com.rep I/RM﹕ construct
07-01 13:55:30.957 11534-11534/com.rep I/RM﹕ onPreExecute
07-01 13:55:30.961 11534-12159/com.rep I/RM﹕ doInBackground
07-01 13:55:30.961 11534-12159/com.rep I/RM﹕ URL DE CONSULTA: http://192.168.1.1/rep/api/clientes
01 13:55:30.962 11534-12159/com.rep I/RM﹕ [Ljava.lang.StackTraceElement;@42088f90
这是代码:
package com.rep.webservice.rest;
import android.content.Context;
import android.util.Log;
import com.rep.model.ClienteModel;
import com.rep.webservice.Servidor;
import com.rep.webservice.volley.AuthFailureError;
import com.rep.webservice.volley.Request;
import com.rep.webservice.volley.RequestQueue;
import com.rep.webservice.volley.Response;
import com.rep.webservice.volley.VolleyError;
import com.rep.webservice.volley.toolbox.JsonObjectRequest;
import com.rep.webservice.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.lang.String.valueOf;
public class ClientesRest extends Servidor {
private String recursoRest = "clientes";
private List arrayClientes;
private RequestQueue mRequestQueue;
private Context context;
public ClientesRest(Context ctx) {
this.context = ctx;
}
public final List getClientes() {
String url = this.URL_WS + recursoRest;
Log.i("RM", "URL DE CONSULTA: " + url);
mRequestQueue = Volley.newRequestQueue(this.context);
JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
parseJSON(response);
Log.i("RM", "resposta da api: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("RM", error.getMessage());
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-TOKEN", "99KI9Gj68CgCf70deM22Ka64chef2Caaa2J0G9JkD0bDAcbFfd19MfacGf3FFm8CM1hG0eDiIk8");
return headers;
}
};
mRequestQueue.add(mJsonObjectRequest);
return this.arrayClientes;
}
private void parseJSON(JSONObject json) {
try {
Log.i("RM", "executou o parseJSON");
/* array para armazenar os clientes */
this.arrayClientes = new ArrayList<ClienteModel>();
/* pega o array "dados" que vem na resposta da consulta ao rest */
JSONArray dados = json.getJSONArray("dados");
/* percorre o array */
for (int i = 0; i < dados.length(); i++) {
/* pega a posição de cada linha no array */
JSONObject item = dados.getJSONObject(i);
/* cria um objeto do tipo ClienteModel */
ClienteModel mClienteModel = new ClienteModel();
/* cadastra os dados necessários no objeto mClienteModel */
mClienteModel.set_idrm(Integer.parseInt(item.optString("id")));
mClienteModel.set_nome(item.optString("nome"));
mClienteModel.set_tipo(item.getString("tipo"));
mClienteModel.set_endereco(item.optString("endereco"));
mClienteModel.set_numero(item.optString("numero"));
mClienteModel.set_complemento(item.optString("complemento"));
mClienteModel.set_cep(item.optString("cep"));
mClienteModel.set_bairro(item.optString("bairro"));
mClienteModel.set_cidade(item.optString("cidade"));
mClienteModel.set_estado(item.optString("estado"));
mClienteModel.set_informacao_adicional("informacao_adicional");
/* adicionar o objeto mClienteModel no array de Clientes "arrayClientes" */
this.arrayClientes.add(mClienteModel);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
最佳答案
这是.toString()
类的默认StackTraceElement
。
您应该使用它的方法来打印堆栈跟踪,或者更好地使用Log
参数,该参数用于在logcat中打印堆栈跟踪。
Log.i("RM", "error", error);