Results 1 to 5 of 5
  1. #1
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default getting the method and the class names (as argument, String varialbe)

    I want to create text file for debug , that will track the flow of my programs.

    for that I want to create a method that can be called from any other method. and its argument are the method and the class names (and other)

    How can I do it ? ( beside manually )

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    How can I do it ? ( beside manually )
    Note sure what you mean by "manually"?

    Anyway, please see the following post on how to debug/log project information:
    Debug challenge: how do you debug a Java program?

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    I have a lot of class and a lot of method . I dont want to write 500 time for each method its name - i can jsut make copy - paste..

    instead of the line in red - i want the line in blue - ( hust instead method_name() and class_name() - a real java method that return the class name

    Java Code:
    public class Student
    {   
      public void setName()
    {
    [COLOR="Red"]DebugClass.writeSomething("Student","setName",otherArguments);[/COLOR]
    [COLOR="Blue"]DebugClass.writeSomething class_name() method_name(),otherArguments);[/COLOR]
    
    ...
    ... 
    }

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    the debug challenge has very good ideas.

    you'd want to code them into a single class and put it in your classpath, then you can import it and reuse the class like a code library.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Have the "debug" class method get the stack trace and take the fourth item.

    Java Code:
    package test;
    
    public class BogusStatic {
    	public static void checkTrace() {
    		StackTraceElement[] st = Thread.currentThread().getStackTrace();
    		System.out.println(st[0].getClassName());
    		System.out.println(st[0].getMethodName());
    		System.out.println(st[1].getClassName());
    		System.out.println(st[1].getMethodName());
    		System.out.println(st[2].getClassName());
    		System.out.println(st[2].getMethodName());
    		System.out.println(st[3].getClassName());
    		System.out.println(st[3].getMethodName());
    	}
    
    	public static void main(String[] args) throws Exception {
    		checkTrace();
    	}
    }
    produces
    Java Code:
    java.lang.Thread
    dumpThreads
    java.lang.Thread
    getStackTrace
    test.BogusStatic
    checkTrace
    test.BogusStatic
    main

Similar Threads

  1. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  2. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  3. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:12 PM
  4. Getting method names using Reflection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-24-2008, 03:18 PM
  5. Method for String to int conversion
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •