写一句异常的语句然后用E.printstacktrack可以知道从哪儿调用的

解决方案 »

  1.   

    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);
        }
    }
      

  2.   

    我记得jdk有一个命令 可以看出 程序运行时的一切 
    忘记了   -verbose试试
      

  3.   

    试一下这个行不行:
    System.out.println("This Class is : " + this.getClass().getName());
    打印出当前类的名称。