Page 1 of 2 12 LastLast
Results 1 to 20 of 31
  1. #1
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default java class constructor is not executed

    Hi all,

    I have the weirdest problem I have ever seen! I'll try to explain.

    I have the following code in my software:


    SendRTPStream rtp = new SendRTPStream( this, loop, call );
    rtp.SetWavFile( wavFile );
    this.rtpMap.put(call.hashCode(), rtp);
    System.out.println("RTP stream created");

    here's part of SendRTPStream and it's constructor:

    public class SendRTPStream implements ControllerListener {
    private CallAgent ca = null;
    private CiscoCall call = null;
    private boolean loop = false;

    SendRTPStream ( CallAgent ca, boolean loop, CiscoCall call) {
    System.out.println("we are in SendRTPStream creator");
    this.localAddress = new SessionAddress();
    this.loop = loop;
    this.ca = ca;
    this.call = call;
    }
    ...etc...
    }


    -----------------------------

    ok, now the strange thing about this is, that when I run my software in Eclipse IDE, everything works fine. and I have output of the SendRTPStream constructor: "we are in SendRTPStream creator".

    but when I compile it in a jar file.
    then I run: java -jar mysoftware.jar

    it never goes inside the constructor...
    it runs. everything actually runs. the other bits of software are functioning OK. and there is NO error message. no indication of some fault.
    but it NEVER goes into the constructor for some reason.

    and I just do NOT understand why... and the problem is I do not even know how to debug this, as it works as supposed to in eclipse.

    Please tell me if you have any idea?

    Thanks,

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: java class constructor is not executed

    Have you tried compiling the code with the javac command? Are you ignoring the IDEs messages?
    Do you have any catch blocks without calls to printStackTrace()?

    For anyone else to see what is happening, you need to make a small simple program that compiles, executes and shows the problem.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: java class constructor is not executed

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Quote Originally Posted by Norm View Post
    Have you tried compiling the code with the javac command? Are you ignoring the IDEs messages?
    Do you have any catch blocks without calls to printStackTrace()?

    For anyone else to see what is happening, you need to make a small simple program that compiles, executes and shows the problem.

    Hi Norm,

    Thanks for your reply.

    Now to answer your questions.
    1) No I'm not ignoring IDE messages.
    2) I do NOT have any catch block without printStackTrace(); //I checked it yesterday, but I'll doublecheck this today again just in case.
    3) Sorry can't make a small software. the software that I'm executing envolves cisco jtapi and some other libraries. so just little code will not work without that. even if I provided the libraries it would not work. because you would need CTI Server, to connect to it before you get to this part of code.

    Thanks again,

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: java class constructor is not executed

    Are you seeing any log messages that use sysout?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Quote Originally Posted by Tolls View Post
    Are you seeing any log messages that use sysout?
    sorry but I don't understand your question!!

    there is no message displayed. no indication of any error.

  7. #7
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Let me explain step by step, how I get to that step in the program, starting from main():

    1) main:
    CallAgent ca = new CallAgent( cti.getMyProvider(), rpName, wavFile, loop );
    ca.setDaemon(true);
    ca.start();

    CallAgent class:
    public class CallAgent extends Thread implements
    CiscoTerminalObserver,
    CiscoAddressObserver, CallObserver,
    MediaCallObserver, CallControlTerminalObserver,
    PhoneTerminalObserver, CallControlCallObserver {
    public CallAgent (MyProvider provider, String deviceName, String wavFile, boolean loop) {
    super ( "CallAgent");
    this.provider = provider;
    this.deviceName = deviceName;
    this.wavFile = wavFile;
    this.loop = loop;
    this.caSelf = this;
    }

    public void run () {
    try {
    initialize();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    public void initialize () {
    try {
    terminal.addObserver(this);
    terminal.addCallObserver(this);
    terminalInService.waitTrue();

    this.address = (CiscoAddress)terminal.getAddresses()[0];
    address.addObserver(this);
    address.addCallObserver(this);
    addressInService.waitTrue();
    }
    catch ( Exception e ) {
    //TODO
    e.printStackTrace();
    }
    }

    @Override
    public void callChangedEvent(CallEv[] events) {
    for ( int i=0; i<events.length; i++ ) {

    switch (events[i].getID()){
    case ConnDisconnectedEv.ID: {
    CiscoCallID callID = ((CiscoCall)events[i].getCall()).getCallID();

    SendRTPStream rtp = this.rtpMap.get(callID.getCall().hashCode());

    if ( rtp != null ) {
    rtp.dispose();
    this.rtpMap.remove(callID.getCall().hashCode());
    System.out.println("Call from DN " + callID.getCall().getCallingAddress() + " Disconnected");
    }
    }
    }
    }

    }

    }

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: java class constructor is not executed

    Are any other messages being printed out to the terminal?
    It's a fairly simple question.
    If you have no other Sstem.out.println() calls, for debugging purposes I would add some all over your code so you can see what's happening.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Quote Originally Posted by Tolls View Post
    Are any other messages being printed out to the terminal?
    It's a fairly simple question.
    If you have no other Sstem.out.println() calls, for debugging purposes I would add some all over your code so you can see what's happening.
    Hi,

    In my last post, I have posted actually a different section of the code:

    so instead of this switch case (ConnDisconnectedEv.ID) in the public void callChangedEvent() function I should have pasted this:

    case CallCtlConnOfferedEv.ID:

    Connection[] conns = ((CiscoCall)events[i].getCall()).getConnections();

    for ( int j = 0; j < conns.length; j++) {
    if ( conns[j].getState() == (Connection.INPROGRESS) )
    {

    CiscoConnection conn = (CiscoConnection)conns[j];
    try {
    conn.accept();
    } catch (InvalidStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (MethodNotSupportedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (PrivilegeViolationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (javax.telephony.ResourceUnavailableException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    CiscoCall call = (CiscoCall)events[i].getCall();

    SendRTPStream rtp = new SendRTPStream( this, loop, call );
    rtp.SetWavFile( wavFile );
    this.rtpMap.put(call.hashCode(), rtp);
    System.out.println("we have set the rtp");

    }
    }
    break;



    and I I have already done the test of putting System.out.println("...") in many places...
    one I had for example just before creating SendRTPStream like this:
    System.out.println("before creating sendrtpstream");
    SendRTPStream rtp = new SendRTPStream( this, loop, call );

    and this one SHOWS fine on the console.

    and then if you remember, in the constructor the very first line is System.out.println("...") <<< see my first post. and this one never shows.

    so something happens before constructor is called. and I do NOT know how to troubleshoot this.

    I have put system print calls in many places, and everything is executed correctly until that constructor.
    and after, no error nothing. it just like the thread goes into sleep straight away without even having time for the constructor??? it's strange.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: java class constructor is not executed

    Well, since I don't read code that isn't in [code] tags [/code] (as pointed out by Darryl's post above) it's not too surprising I haven't seen the printlns.
    Can you do some code in which there are printlns before and after the creation of the object (ie in whatever class the constructor is called from), and post both that code and the output so we can see exactly what's oging on on a single run?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: java class constructor is not executed

    the thread goes into sleep
    Can any of the constructors block and not return?
    Does the println before a constructor print something and the one after the constructor not print because the constructor never returned?
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Norm,

    Yes, the println before constructor prints just fine.
    and the first println inside constructor does NOT print.
    and the println after constructor is never reached either.

    sorry for not posting properly with I'll do it now again:

    step 1 main:
    Java Code:
    CallAgent ca = new CallAgent( cti.getMyProvider(), rpName, wavFile, loop );
    ca.setDaemon(true);
    ca.start();
    step 2:
    Java Code:
    CallAgent class:
    public class CallAgent extends Thread implements
    CiscoTerminalObserver,
    CiscoAddressObserver, CallObserver,
    MediaCallObserver, CallControlTerminalObserver,
    PhoneTerminalObserver, CallControlCallObserver {
    public CallAgent (MyProvider provider, String deviceName, String wavFile, boolean loop) {
    super ( "CallAgent");
    this.provider = provider;
    this.deviceName = deviceName;
    this.wavFile = wavFile;
    this.loop = loop;
    this.caSelf = this;
    }
    
    public void run () {
    try {
    initialize();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    public void initialize () {
    try {
    terminal.addObserver(this);
    terminal.addCallObserver(this);
    terminalInService.waitTrue();
    
    this.address = (CiscoAddress)terminal.getAddresses()[0];
    address.addObserver(this);
    address.addCallObserver(this);
    addressInService.waitTrue();
    }
    catch ( Exception e ) {
    //TODO
    e.printStackTrace();
    }
    }
    
    @Override
    public void callChangedEvent(CallEv[] events) {
    for ( int i=0; i<events.length; i++ ) {
    
    switch (events[i].getID()){
    case CallCtlConnOfferedEv.ID:
    
    Connection[] conns = ((CiscoCall)events[i].getCall()).getConnections();
    
    for ( int j = 0; j < conns.length; j++) {
    if ( conns[j].getState() == (Connection.INPROGRESS) )
    {
    
    CiscoConnection conn = (CiscoConnection)conns[j];
    try {
    conn.accept();
    } catch (InvalidStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (MethodNotSupportedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (PrivilegeViolationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (javax.telephony.ResourceUnavailableException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    CiscoCall call = (CiscoCall)events[i].getCall();
    
    System.out.println("this one prints fine");
    SendRTPStream rtp = new SendRTPStream( this, loop, call );
    System.out.println("this one DOES NOT PRINT");
    rtp.SetWavFile( wavFile );
    this.rtpMap.put(call.hashCode(), rtp);
    System.out.println("we have set the rtp");
    
    }
    }
    break;
    }
    }
    
    }
    
    }
    and finally I'll paste again the SendRTPStream class constructor:

    Java Code:
    public class SendRTPStream implements ControllerListener {
    private CallAgent ca = null;
    private CiscoCall call = null;
    private boolean loop = false;
    
    SendRTPStream ( CallAgent ca, boolean loop, CiscoCall call) {
    System.out.println("we are in SendRTPStream creator");
    this.localAddress = new SessionAddress();
    this.loop = loop;
    this.ca = ca;
    this.call = call;
    }
    }

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: java class constructor is not executed

    Can you post what is printed out?
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    output:

    C:\Users\lostchild\workspace>java -jar callenforce.jar
    Initializing provider --- OK
    Call Agent Initialization --- OK
    log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.failover.FailoverTr ansport).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See Apache log4j 1.2 - Frequently Asked Technical Questions for more info.
    this one prints fine
    Answering TerminalConnection [RP_APP/[1000::1/(P1-ctiuser) GCID=(1,8011)->ACTIVE]->ALERTING]->RINGING

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: java class constructor is not executed

    Is there more than one definition for the SendRTPStream class? Delete the .class file and recompile it.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: java class constructor is not executed

    That's what I'm starting to wonder.
    There's nothing in the constructor that would prevent that println() from executing, so if it isn't executing then that code is not being run, which implies it is not that version in your jar file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    nope, there is only one definition of this class...

    I do understand what you are saying. but how is it possible that it runs fine in IDE?? exactly same code? no changes at all?
    also this class is part of the project. so I don't even need an import for it.

    I have now deleted the class file, and added it again. same result.

  18. #18
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    I would really appreciate if someone could take his time to help me with this.
    maybe in the evening if you have time we could do a session on skype or on teamviewer or something?
    I can't do it where I am right now, as that kind of communications are blocked.
    but I would do it in about 5 hours from now.
    if anyone can help, e-mail me please on goglidze at gmail dot com

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: java class constructor is not executed

    Can you make a small, complete program that compiles, executes and shows the problem. To test this there needs to be executable code that shows the problem.

    The problem sure looks like multiple versions. To test that possibility, give the class a new name (say add XX to the name) and use that new name in the code.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    lostchild is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: java class constructor is not executed

    Norm,

    As I already mentioned to execute this, you need cisco callmanager. it won't work otherwise.
    so I can't provide small executable code that works.

    I just added new Class XXSendRTPStream. copied the contents of the old class. and DELETED the old class. - and I still have same problem.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 05-08-2012, 10:40 PM
  2. My first java program could not be executed..help
    By miaaa00 in forum New To Java
    Replies: 7
    Last Post: 03-21-2011, 09:07 AM
  3. Accessing Constructor from another Class
    By Java-Guy in forum New To Java
    Replies: 4
    Last Post: 01-19-2011, 05:41 AM
  4. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 10:01 AM

Posting Permissions

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