Again on "call to this must be first statement in constructor"

Hi, I've spent the last hour reading tons of docs & threads about the "call to this must be first statement in constructor" problem, but I still cannot work it out.
Here is the code
     public Orologio(String s)
          StringTokenizer exploder=new StringTokenizer(s,":",false);
          this(Integer.parseInt(exploder.nextToken()),Integer.parseInt(exploder.nextToken()));
          }Well, I know this..() must be the first line in the method, but I need to parse my input string before passing the parameters to the Orologio(int,int) constructor!
Thankyou!

You could define an initialization method:private void init(int a, int b) {
    ... your initialization code that was in your constructor...
public Orologio(String s) {
    StringTokenizer exploder=new StringTokenizer(s,":",false);
    init(Integer.parseInt(exploder.nextToken()),Integer.parseInt(exploder.nextToken()));
public Orlogio(int a, int b) {
    init(a, b);
}However, make sure it is the responsability of this class to handle String as constructor parameter. Maybe you should force the client to tokenize the string and provide integer values to the constructor (and then get rid of the Orologio(String s) constructor.)

Similar Messages

  • "call to this must be first statement in constructor"

    Here's the code:
    public class TAGEmail {
        private StringBuilder sTO = new StringBuilder();
        public TAGEmail()
        public void setTO(String sRecipient)
            this( sRecipient, true );
        public void setTO(String sRecipient, boolean bAppend)
            String sRegexPattern = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$";
            Pattern oPattern = Pattern.compile(sRegexPattern, Pattern.CASE_INSENSITIVE);
            Matcher oMatcher = oPattern.matcher(sRecipient);
            if( ! oMatcher.find() )
                oLogger.addEntry(2,"Email address '" + sRecipient + "' is not a valid e-mail address!");
            if( sTO.equals(null) || bAppend )
                sTO.append( "\"" + sRecipient + "\"" );
            else
                sTO.delete( 0, sTO.length() );
                sTO.append( "\"" + sRecipient + "\"" );
    }The part I don't get is that it's not in a constructor...and it is the first line of the method it's in. Am I missing something?

    Ah. My thought process was just the opposite. If
    the compiler is going to add it anyway, I'll just do
    it now. Symantics, I suppose.Well, the compiler doesn't add it into the source code. It simply interprets the two expressions identically. (It might be possible that something is hiding or shadowing the method so that this. is necessary for disambiguation. I've only seen that with variables though. I don't know if it can ever be an issue with methods. If it happens, I'd say something is poorly named.)

  • Call to super must be first statement in constructor

    Why i've receive this message if the code of the constructor is that:
    public void Angulo(String Base){
         super(Base);
    The call to superclass constructor is the first statement on this function.
    Can somebody helpme? Thanks

    Hi,
    This is a regular function and not a constructor. If it is, then it should be
    public Angulo(String Base){
    super(Base);
    Hope this helps,
    Kurt.

  • Call to super must be first statement

    I'm new to Java and I have a question regarding super(). I'm implementing a design where we have a custom exception which extends Exception. The design calls for null messages to lead to throwing an IllegalArgumentException, but Exception's constructor does not throw an IllegalArgumentException for a null message.
    Here is what I want to do, but not allowed to since super must be the first statement in the constructor:
    public CustomException(String message) {
        if (message == null) {
            throw new IllegalArgumentException("message cannot be null.");
        super(message);
    }I could call super first and then throw an exception if the message is null, but that doesn't seem like a good solution.

    public CustomException(String message) {
        super(nullCheck(message));
    static String nullCheck(String message) {
        if (message == null) {
            throw new IllegalArgumentException("message cannot be null.");
        return message;
    }

  • Super- first statement in constructor.

    my compiler (Jcreator LE) doesn't seem to recognize that super is the first statement in the constructor, and gives me an error message (the same thing happens using the this keyword).
    public void Student(String str, int day, int mo, int yr, String maj)
    super(str,day,mo,yr);
         major=maj;
         return;
    With that code as the constructor, I get this error message
    C:\Java\JCreator le\MyProjects\Lab 5\Student.java:8: call to super must be first statement in constructor
              super(str,day,mo,yr);
    If anybody has any ideas why this is happening or what I can do to correct it, I would appreciate it.
    Thanks,
    Gareth

    You are trying to call a method.
    Instead you have to use super( ) to controll the construction
    of a parent class part of an object.
    Code is something like this:
    class Student {
      public Student(String str) {
         // initialize this object using str
      public Student(int day) {
        // initialize this object using day
    class FromStudent extends Student {
        public FromStudent(String str) {
           // pass control to Student constructor
           super(str);  // the first constructor here
        public FromStudent(int day) {
           // pass FromStudent to Student constructor
          super(day);  // the first constructor here

  • SET TRANSACTION must be first statement of transaction

    I am using oracle8i db with sun one 7.0. i use the oracle thin driver to talk to the db. i have bunch of session beans which uses the oracle data source. when i invoke the session bean, i get this ORA-01453 error.
    Here is my jdbc properties:
    <jdbc-connection-pool steady-pool-size="8" max-pool-size="32" max-wait-time-in-millis="60000" pool-resize-quantity="2" idle-timeout-in-seconds="300" is-isolation-level-guaranteed="true" is-connection-validation-required="true" connection-validation-method="table" fail-all-connections="false" datasource-classname="oracle.jdbc.xa.client.OracleXADataSource" name="JSBContainerPool" res-type="javax.sql.XADataSource" validation-table-name="dual" transaction-isolation-level="read-committed">
    <property value="jdbc:oracle:thin:@muruga:1521:DEV" name="URL"/>
    <property value="muruga" name="User"/>
    <property value="muruga" name="Password"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" pool-name="JSBContainerPool" jndi-name="jdbc/JSBContainerDataSource"/>
    Error message:
    The exception reported is: "java.sql.SQLException: ORA-01453: SET TRANSACTION
    must be first statement of transaction
    WARNING: CORE3283: stderr: at oracle.jdbc.dbaccess.DBError.throwSqlExceptio
    n(DBError.java:168)
    WARNING: CORE3283: stderr: at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.j
    ava:208)
    WARNING: CORE3283: stderr: at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543
    WARNING: CORE3283: stderr: at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Pro
    tocol.java:1405)
    WARNING: CORE3283: stderr: at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFet
    ch(TTC7Protocol.java:822)
    WARNING: CORE3283: stderr: at oracle.jdbc.driver.OracleStatement.executeNon
    Query(OracleStatement.java:1446)
    WARNING: CORE3283: stderr: at oracle.jdbc.driver.OracleStatement.doExecuteO
    ther(OracleStatement.java:1371)
    WARNING: CORE3283: stderr: at oracle.jdbc.driver.OracleStatement.doExecuteW
    ithTimeout(OracleStatement.java:1900)
    WARNING: CORE3283: stderr: at oracle.jdbc.driver.OracleStatement.execute(Or
    acleStatement.java:737)
    WARNING: CORE3283: stderr: at oracle.jdbc.driver.OracleConnection.setTransa
    ctionIsolation(OracleConnection.java:1081)
    WARNING: CORE3283: stderr: at com.sun.enterprise.resource.Jdbc20XaAllocator
    $ConnectionWrapper.setTransactionIsolation(Jdbc20XaAllocator.java:196)

    In the connection pool setting in Admin server under the section Transaction Isolation deselect the option "Guarantee Isolation Level" .This should solve the problem.
    regards
    Kris

  • JdbcRowSetXImp (..): SET TRANSACTION must be first statement of transaction

    Hi.
    Im running JSC created application and getting in the log file this messages:
    [date & time] warning (24167): CORE3238: stderr: JdbcRowSetXImpl (setTransactionIsolation): [Sun][Oracle JDBC Driver][Oracle]ORA-01453: SET TRANSACTION must be the first statement of transaction
    As you may see, Im using JSC JDBC drivers. Im running on Sun One Web Server version 6.1 sp2 on Linux RedHat 3Ent. The application was builded with JSC me with latest patch applied.
    It seems a bug in the JdbcRowSetXImpl.
    Has someone similar problem?
    Regards.

    Hi John.
    This message is present on all log file a few days after the application began in production use, almost a month ago.
    The only change done in the configuration few days after the app was deployed was "Guarantee Isolation Level" in the JDBC connection pool configuration, switched from OFF to ON.
    Yesterday I turn OFF again and have no more messages about SET TRANSACTION...
    I guess that the SET TRANSACTION is issued two times, one by the web server before giving the connection to the app then by the row set impl.
    I will let you known if the messages appears again (I guess not).
    Regards.

  • Any idea why super() and this() needs to be first statement

    Java recommends super() and this() to be the first statement to be used.why this design constraint is imposed?
    This imposes one more restriction
    where super() and this() cannot be used at the same time?
    how this constraint is useful.
    for eg:
    class A
         A(int a)
         System.out.println("A(int)");
         A(int a,int b)
         System.out.println("A(int,int)");
    class B extends A
         B()
              super(1);
              System.out.println("B()");
         B(int i)
              this();
              super(1,1);//compile-error :must be first statement
    the above eg may be a bad design,but are the constraints imposed for this purpose?or anything else?

    To make sure that the constructor is the first thing that runs, and to make sure >the super instance is completely constructed before we do anything with the >child instance.
    Both these go toward having the object be in a consistent, valid state.I accept the point,but considering the code part
    B()
       //super(1);
    System.out.println("B()");
    B(int i)
    super(1,1);
    this();
    }in above super instance will be constructed first followed by this().
    but this() cannot be used as second statement???
    I feel ,this is because this() in turn calls the super constructor again?to restrict this constraint made?is it something like that?

  • An error has occurred while accessing SQL database or system resources. If this is the first time you have seen this message, please try again later. If this problem persists, please contact your administrator.

    I have SP Server 2010, and when I try to DELETE a rule within an existing Audience, "Property (Account Name) = domain/username", I get this error, "An error has occurred while accessing SQL database or system resources. If this
    is the first time you have seen this message, please try again later. If this
    problem persists, please contact your administrator."  When I try to "MODIFY" the rule I get this error, "One or more values typed on this page are not valid. Check the text for the indicated fields." 
    The last time I checked it was working, I'm not aware of any new updates installed recently?  I did a full Profile Synchronization as well, but still not working, please advise? -- Evenstarline

    Hi Sara,
    First of all thank you very much for your prompt responses. Here are my comments to each of your suggestions below, and just to let you know I am using a Farm Admin account.  I
    was able to do this way after we upgraded from SP 2007 to SP 2010 as well.   I would like to mention I'm not a SP expert, just been given the responsibility due to another person handling it just left, so apologize with some of
    my novice questions below?
    1. When I change the Operators to "Contains" or "Not Contains" get generates this error below.
         Error generating in red towards top of the audience page..."One or more values typed on this page are not valid.  Check the text for the indicated fields."
         Error occurred where you enter your "Value"..."Could not resolve the user identity. Please re-enter the account name."
    2. We have a 3-server-tier topology (SPWeb, SPDB, and SPFarm).  Does the updates only apply to where the Central Admin is installed, which is the "SPFarm"?  I checked all
    3 servers, and NONE of the updates (KB2899494, KB2889845, and KB2883055) you'd mentioned are installed.
    3. I'm new to IISRET, I need to be extra cautious of what I run in production, is this safe to run with no problem?  What does it do?  And How do I run it?
    4. I'm also new to viewing the ULS log.  I'd just downloaded a viewer for it.  I'm assuming the only logs I need to be concern with viewing are within the SPAdmin (where Central
    Admin is installed)?  There's so many of them, what should I be looking for exactly?
    Evenstarline 

  • I can't access iCloud, i keep getting a message to try again later. This is the first time i have tried to log into icloud. I  know my account is working, i want to access it from my macbook. I think its looking for my old icloud email, what to do?

    I can't access iCloud, i keep getting a message to try again later. This is the first time i have tried to log into icloud. I  know my account is working, i want to access it from my macbook. I think its looking for my old icloud email, what to do? I have a working apple id, i dont understand, could it be linked to an old account iD?

    Hi smccarrison,
    Thanks for visiting Apple Support Communities.
    You may find the steps in this article helpful with troubleshooting signing into iCloud:
    iCloud: Account troubleshooting
    http://support.apple.com/kb/TS3988
    All the best,
    Jeremy

  • I went to make a call this morning, and all my contacts have disappeared! How can I can them back? I only just entered them all the other day, this is my first iphone

    I went to make a call this morning and all my contacts have disappeareed, how do i get them back? This is my first iphone (4s) and i only just entered them all manually 4 days ago! Please help me!

    I entered them directly into my phone. Two days ago, I plugged it into my mac and synced it with itunes, but i didn't sync the contacts and they were still in there after.

  • Some of my contacts are not displayed in my contact list, but I know they're in memory because when one of them calls me my phone recognizes the caller.  This happened a few days ago, so i must have changed some setting,but I have no idea which one. Help?

    Recently some of my contacts are no longer displaying in my contact list, but I know they're in memory because when one of them calls me my phone recognizes the caller.  This happened a few days ago, so i must have changed some setting,but I have no idea which one. Can anyone help?

    Why start a new and very similar thread to your other one which you have not responded to (have you read the replies?)
    I suggest that no response is made to this duplicate thread. 

  • I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first p

    I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first place can someone please explain and tell me how to make it work again

    Sorry first time asking question didn't mean to write same thing twice well copy paste

  • When i want to install windows7 on my snow leopard(10.6.4) with boot camp assistant,said that you must update your mac,i do this and try to install windows7 again but i have this problem again?what can i do?

    when i want to install windows7 on my snow leopard(10.6.4) with boot camp assistant,said that you must update your mac,i do this and try to install windows7 again but i have this problem again?what can i do?

    Graham Giles wrote:
    Have you seen this type of problem before? I think it could be a serious issue for anyone in a similar position.
    No; but then, I've not had occasion to use TDM. I've been using firerwire drives for over 10 years, both FW400 and FW800, with no issues except a bit of instability using a B&W G3 machine.
    TDM should be safe. Using cautious, manual copying of files from the Target machine to the Host machine should not result in unexpected loss of files or damage to the Target drive's directories. It should behave exactly the same as if it were an external (to the Host) firewire drive.
    •  I don't suppose there is anything I can do to 'put back' lost items from a separate Time Machine drive which has an up to date backup on it.
    There is probably a way to do that - seems to me that's one of the reasons for a Time Machine volume.
    On the other hand, if the Time Machine volume is rigidly linked to the now-absent OS on the original drive, there may be no way to effectively access the files in the TM archive.
    I know that using a cloned drive would work well in this instance.
    I have no experience with Time Machine, so perhaps someone who has will chime in with suggestions.
    With the machine in TDM with the other machine, have you tried running Disk Utility to see if you can effect repairs to the drive?

  • Hello this is the first time I have ever had a problem. I am trying to down load a movie and it keeps giving me error -50. I have signed out and back in and deleated the download and tryed again and still will not download.

    Hello this is the first time I have ever had a problem. I am trying to down load a movie and it keeps giving me error -50. I have signed out and back in and deleated the download and tryed again and still will not download.

    Perhaps try the "Error -50," "-5000," "8003," "8008," or "-42023" section in the Specific Conditions and Alert Messages: (Mac OS X / Windows) section of the following document:
    iTunes: Advanced iTunes Store troubleshooting

Maybe you are looking for

  • Volume keys will not work with incoming calls on headphones

    So the headphone that came with my iPhone 4s, and others of the same type I have used, will not allow me to lower the volume of the caller. I would be listening to my music or something, it could even be at 50% volume, however the incoming call pushe

  • Problem running after updating iTunes

    I have uninstalled and re-installed iTunes multiple times, but continue to get the message: "iTunes cannot run because some of its required files are missing.  Please reintall iTunes." This all began after updating iTunes.

  • Query for create manual tabular form using apex collection using item textfield with autocomplete

    can we create a manual tabular form inside item textfield with autocomplete ? how it is possible? with Apex_item API used for this item. i used this code for creat  cascading select list select seq_id, APEX_ITEM.SELECT_LIST_FROM_QUERY(         p_idx 

  • Lion quarantine causing applications to not launch/open

    Hello all, I seem to have tripped over this quarantine bug in Lion. Newly downloaded apps simply sit in the Dock with the sphere pulsing, and disappear when clicked on. I've found a few places that talk about possible workarounds with Terminal, but h

  • MAC Exception for Web Authentication

    Hello folks.  I currently have a guest network setup using guest tunneling and an anchor controller.  I have it configured for web authentication.   So basically, a client associates to the SSID, obtains an DHCP IP from the guest anchor controller, a