說明
Jni列印日志到Logcat,都是使用如下的宏定義:
#include <android/log.h>
#ifndef LOG_TAG
#define LOG_TAG
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#endif
錯誤代碼
double x = 381;
LOGE("fengyuzaitu", "x:%d", x);
列印的結果是一個非常龐大的資料,實際上列印一個浮點型應該使用%f,而不是使用%d
double x = 381;
LOGE("fengyuzaitu", "x:%f", x);
實際的應用環境中,可能x的定義離列印非常遠,需要注意
Logcat顯示的日志必須是UTF-8編碼,是以可以看到列印GBK編碼的情況下,會出現亂碼,是以有必要進行轉碼顯示
本文轉自fengyuzaitu 51CTO部落格,原文連結:http://blog.51cto.com/fengyuzaitu/1409603,如需轉載請自行聯系原作者