Android how to view long string in logcat

怎甘沉沦 提交于 2019-12-12 13:58:51

问题


I have a HashMap<String, LinkedHashMap<String,String> that is fairly long (not an issue) and I'm trying to make sure things look correct before I use the data inside it. To do this I'm trying to just attempting to do this Log.v("productsFromDB",products.toString()) but in the LogCat It shows about 1/3 of it. Is there a way to output the entire map?


回答1:


Logcat can only show about 4000 characters. So you need to call a recursive function to see the entire hashmap. Try this function:

public static void longLog(String str) {
    if (str.length() > 4000) {
        Log.d("", str.substring(0, 4000));
        longLog(str.substring(4000));
    } else
        Log.d("", str);
}


来源:https://stackoverflow.com/questions/24636089/android-how-to-view-long-string-in-logcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!