一个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());打印出当前类的名称。 跪求 高手 帮帮忙 这两种写法等价吗?关于 new 类名(); 如何把Swing组件上的显示画面保存成一个图象image对象 HSSFWorkbook初始化失败 jDialog显示的问题,大家看看呀 怎么会抖动 估计是repaint方法的原因 菜鸟一问 在JBuilder中如何做到一个applet调用另外一个applet DataInputStream与BufferedInputStream两个流有什么区别? 正则匹配小问题-java 面向对象问题的两个巨大疑惑? 寻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());
打印出当前类的名称。