Results 1 to 7 of 7
  1. #1
    aleplgr is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default why does not execute this?

    Hi! In this code I print one message before and after executing the method obtenirInstanciaUnica, those 2 messages are actually displayed in the console, so far so good:

    Java Code:
    private void jbInit() throws Exception  {
    System.out.println("before obtenirInstanciaUnica");
        gestor = GestorKlass.obtenirInstanciaUnica(Integer.parseInt(param.obtenirMaximMatrius()));
       System.out.println("after obtenirInstanciaUnica");
    Here's the method, in the constructor GestorKlass I try to display a message

    Java Code:
    public static synchronized GestorKlass obtenirInstanciaUnica(int maxMats){
     System.out.println("I AM HEREEEEEEE");
        if (instancia == null)
    	instancia = new GestorKlass(maxMats);
        return instancia;
      }
     
     private GestorKlass(int max){
      System.out.println("I AM CONSTRUCTING HERE");
        maxMatrius = max;
        numMatriusOcupades = 0;
        matriusCarregades = new GestorMatriu[maxMatrius];
      }
    The question is WHY does not it write anything else to the console? it should show the message in the obtenirInstanciaUnica method first line, and also the message in the constructor, seems as if this method is not executed, but it is because It returns the gestor variable which is used all around the rest of the program and it works fine, I don't understand ..
    Last edited by levent; 07-31-2007 at 09:07 PM. Reason: Codes are placed inside [code] tag.

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Very odd. My suspicion is that the problem lies outside the code you have presented. Can you post the entire GestorKlass?

  3. #3
    levent Guest

    Default

    Make sure you recompile the project properly. I think you should try deleting all class files and recompiling the sources.

  4. #4
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    haha i cant believe noone saw it, but after you declare what condition the if statement must meet you need curly braces.

    if (condition)
    {
    Do stuff here;
    }

  5. #5
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    That is incorrect.
    Java Code:
    if (condition)
      Do this;
    Is perfectly valid code. Braces are only required if the code in the condition is more then one line.

  6. #6
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    Oh really? thanks i never knew

  7. #7
    aleplgr is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    Thanks, I deleted the class files and recompiled and it works fine now!!

Similar Threads

  1. cannot execute EJB application.
    By JavaEmpires in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-17-2008, 10:53 AM
  2. Execute Jar file
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:13 AM
  3. My application Will Not Execute
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:16 AM
  4. problems when I try to execute a jsp page
    By christina in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-01-2007, 01:23 PM
  5. Execute a new program in java
    By mathias in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 06:42 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
  •