gpt4 book ai didi

java - Ljava.lang.StackTraceElement 调试安卓应用

转载 作者:行者123 更新时间:2023-11-29 21:06:06 25 4
gpt4 key购买 nike

我正在尝试调试我的应用程序以查看它停止运行的位置,但我对以下日志“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();
}


}
}

最佳答案

它是 StackTraceElement 类的默认 .toString()

您应该使用它的方法来打印堆栈跟踪,或者更好的是,使用用于在 logcat 中打印堆栈跟踪的 Log 参数。

Log.i("RM", "error", error);

关于java - Ljava.lang.StackTraceElement 调试安卓应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24515803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com