logcat提示信息分以下几种
verbose 提醒
debug 调试
info 信息
warn 警告
error 错误
分别对应不同的颜色
我们测试的时候可以使用Log类显示提示信息
分别对应
log.v(tag,message);
log.d(tag,message);
log.i(tag,message);
log.w(tag,message);
log.r(tag,message);
如下述代码
package com.example.test822ceshi.server;
import android.util.Log;
public class Calculator {
private String tag="Calculator";
public int add(int x,int y)
{
Log.v(tag, "x= " +x);
Log.d(tag, "y= " +y);
int result = x+y;
Log.e(tag, "x+y= "+result);
Log.i(tag, "x+y= "+result);
Log.w(tag, "x+y= "+result);
return x+y;
}
public Calculator() {
// TODO Auto-generated constructor stub
}
// public static void main(String[]args)
// {
// System.out.println("haha");
// }
}
其中tag是标签
我们在logcat中点击绿色的加号,创建新的过滤器,其中的by log cat里填上自己预设的标签,如图
运行测试run as junit之后,就会显示如下提示信息