【发布时间】:2015-05-15 20:52:56
【问题描述】:
我编写了一个创建 JSONObject 的方法,该方法曾经可以工作。突然间我表现得很奇怪。使用调试器,我可以到达返回创建的 JSONObject 的行,但它总是跳转到返回 null 的最后一行,而不进入 catch 块。调试器告诉我创建的对象是一个有效的 JSONObject。
import org.json.JSONObject;
...
JSONObject returnJson = new JSONObject();
try {
returnJson.put("event", event);
returnJson.put("list", jsonArray);
returnJson.put("type", "list");
returnJson.put("container", container);
Log.d(TAG, "created");
Log.d(TAG, returnJson.toString());
return returnJson;
} catch (JSONException e) {
Log.e(TAG, e.getMessage(), e);
}
Log.d(TAG, "null returned"); // never called in the non-debugging mode
return returnJson;
【问题讨论】:
-
它是否在调试器中正常工作not?也许调试器正在使用的源与类文件不同步......
-
我不这么认为。因为我无法调试,我只能猜测,但 porject 的行为就像没有返回 json 对象一样。无论如何,我清除了所有缓存并重新启动,我无法以这种方式解决任何可能的不同步问题。
-
你可以很容易地添加 logging 来看看它到底能走多远,而无需调试......
-
在流程、调试或其他方面不应有任何差异。如果您在非调试模式下运行应用程序,它仍然有效吗?
-
是的,它在非调试模式下工作。我编辑了这个问题。最后一个日志永远不会被调用。那么我该如何解决调试问题呢?
标签: java debugging android-studio