一个class运行时,怎么知道该class是被谁调用的? 写一句异常的语句然后用E.printstacktrack可以知道从哪儿调用的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main(String[] args){ method1();}public static void method1(){ try { throw new Exception(); } catch(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); String trace = sw.toString(); int index1 = trace.indexOf("\tat "); int index2 = trace.indexOf(System.getProperty("line.separator"), index1 + 4); String lastCall = trace.substring(index1 + 4, index2); int index3 = lastCall.indexOf('('); String caller = lastCall.substring(0, index3); System.out.println("caller is: " + caller); }} 我记得jdk有一个命令 可以看出 程序运行时的一切 忘记了 -verbose试试 试一下这个行不行:System.out.println("This Class is : " + this.getClass().getName());打印出当前类的名称。 可变参数的一个警告问题 初学:怎么把string里的中文去掉然后只留8位数字,内详 验证字符串只含数字和小数点的正则表达是。。。。? 如何调用动态的生成的类的方法(个人觉得很头疼的问题) 求救:一个网页制作的问题 请教:如何算周末日期 http://user1.7host.com/garning/360/kuangri.htm这个页面里的放大和缩小是怎么实现的? 为什么我抄书上的例子都有问题? JBuilder里有没有象VC里,分DEBUG和Release牌呢? eclipse改包名后为什么包有个加号? 面向对象问题的两个巨大疑惑? 寻together6.2 for eclipse 注册机
{
method1();
}public static void method1()
{
try
{
throw new Exception();
}
catch(Exception e)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
String trace = sw.toString(); int index1 = trace.indexOf("\tat ");
int index2 = trace.indexOf(System.getProperty("line.separator"), index1 + 4);
String lastCall = trace.substring(index1 + 4, index2);
int index3 = lastCall.indexOf('(');
String caller = lastCall.substring(0, index3);
System.out.println("caller is: " + caller);
}
}
忘记了 -verbose试试
System.out.println("This Class is : " + this.getClass().getName());
打印出当前类的名称。