"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.)

Similar Messages

  • 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.)

  • 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?

  • 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. 

  • Alright,so i lost my ipod and with icloud i found it... this is the first time this has happpen to me. Should i call the cops for they could recover it or another option ?

    Alright,so i lost my iPod and with icloud i found it... this is the first time this has happen to me. Should i call the cops for they could recover it or another option ?

    Hi Odd_Franky,
    Welcome to the Apple Support Communities!
    Please follow the recommendations in the following article if your iOS device is lost or stolen.
    If your iPhone, iPad, or iPod touch is lost or stolen
    http://support.apple.com/kb/HT5668
    Have a great day,
    Joe

  • I just got a new phone I went to purchase a song and it said since you have a new device this is your first purchase you must answer the security questions I don't remember the answers to the questions what do I do

    I just get a new phone I wait to pie a song and my phone said this is your first purchase on this device so you have to answer these two security questions but I don't know what the answers are to the question I forget so how do I change them so I can purchase stuff

    You need to ask Apple to reset your security questions; this can be done by clicking here and picking a method, or if your country isn't listed, filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (109133)

  • SQLException: After clearParameters() has been called, all parameters must be reset before executing

    Hi,
    I am running: Weblogic 6.1, SP2
    Driver : weblogic.jdbc.oci.Driver
    Reason for not using the "thin" driver, which works, is limit
    on size of Clob
    Previous references to this problem in this newsgroup indicate driver problems
    with older versions of WL.. I am using the latest..
    The SQLException I get is "After clearParameters() has been called, all parameters
    must be reset before executing". This happens the second time the code below is
    excuted ( ok the first time )
    "clearParameters()" is never called explicitly in my code.
    The exception occurs on the "spFunc.execute();" statement at the very end of this
    code:
    // OBS:connection, conn_, is opened from a connection pool
    before this code is called and cloesed afterwards.
    conn_.setAutoCommit(false);
    // ============== Initializing clob ==================
    SerialStatement stmt = (SerialStatement)conn_.createStatement();
    stmt.execute("INSERT INTO lc_clob_temp VALUES (1, EMPTY_CLOB())");
    // OBS: using a prepared statement here will result in SerialClob
    // exception when using setClob in the prepared statement
    below
    // This is probably a bug ( worked in WL 5.1 ). We had this
    as a support case 270952 with WebLogic.
    stmt.execute("SELECT * FROM lc_clob_temp WHERE id = 1");
    ResultSet crs = stmt.getResultSet();
    weblogic.jdbc.rmi.SerialClob xmlClob = null;
    while ( crs.next() ) {
    xmlClob=(weblogic.jdbc.rmi.SerialClob)crs.getClob("newclob");
    // Call Oracle's stored procedure for calling Oracle XSU.
    SerialCallableStatement spFunc =
    (SerialCallableStatement)conn_.prepareCall(
    "declare " +
    "insCtx sys.DBMS_XMLSave.ctxType; " +
    "begin " +
    "insCtx := sys.DBMS_XMLSave.newContext(?); " +
         "sys.DBMS_XMLSave.setBatchSize(insCtx,0);" +      "sys.DBMS_XMLSave.setCommitBatch(insCtx,
    0);" +
    "? := sys.DBMS_XMLSave.insertXML(insCtx,?); " +
    "sys.DBMS_XMLSave.closeContext(insCtx); " +
    "end;"
    spFunc.setString(1, viewName );
    spFunc.registerOutParameter (2, Types.NUMERIC);
    Writer outstream = xmlClob.getCharacterOutputStream();
    outstream.write(xml.toString());
    outstream.flush();
    outstream.close();
    spFunc.setClob( 3, xmlClob);
    spFunc.execute();
    spFunc.close();

    Hi,
    I am running: Weblogic 6.1, SP2
    Driver : weblogic.jdbc.oci.Driver
    Reason for not using the "thin" driver, which works, is limit
    on size of Clob
    Previous references to this problem in this newsgroup indicate driver problems
    with older versions of WL.. I am using the latest..
    The SQLException I get is "After clearParameters() has been called, all parameters
    must be reset before executing". This happens the second time the code below is
    excuted ( ok the first time )
    "clearParameters()" is never called explicitly in my code.
    The exception occurs on the "spFunc.execute();" statement at the very end of this
    code:
    // OBS:connection, conn_, is opened from a connection pool
    before this code is called and cloesed afterwards.
    conn_.setAutoCommit(false);
    // ============== Initializing clob ==================
    SerialStatement stmt = (SerialStatement)conn_.createStatement();
    stmt.execute("INSERT INTO lc_clob_temp VALUES (1, EMPTY_CLOB())");
    // OBS: using a prepared statement here will result in SerialClob
    // exception when using setClob in the prepared statement
    below
    // This is probably a bug ( worked in WL 5.1 ). We had this
    as a support case 270952 with WebLogic.
    stmt.execute("SELECT * FROM lc_clob_temp WHERE id = 1");
    ResultSet crs = stmt.getResultSet();
    weblogic.jdbc.rmi.SerialClob xmlClob = null;
    while ( crs.next() ) {
    xmlClob=(weblogic.jdbc.rmi.SerialClob)crs.getClob("newclob");
    // Call Oracle's stored procedure for calling Oracle XSU.
    SerialCallableStatement spFunc =
    (SerialCallableStatement)conn_.prepareCall(
    "declare " +
    "insCtx sys.DBMS_XMLSave.ctxType; " +
    "begin " +
    "insCtx := sys.DBMS_XMLSave.newContext(?); " +
         "sys.DBMS_XMLSave.setBatchSize(insCtx,0);" +      "sys.DBMS_XMLSave.setCommitBatch(insCtx,
    0);" +
    "? := sys.DBMS_XMLSave.insertXML(insCtx,?); " +
    "sys.DBMS_XMLSave.closeContext(insCtx); " +
    "end;"
    spFunc.setString(1, viewName );
    spFunc.registerOutParameter (2, Types.NUMERIC);
    Writer outstream = xmlClob.getCharacterOutputStream();
    outstream.write(xml.toString());
    outstream.flush();
    outstream.close();
    spFunc.setClob( 3, xmlClob);
    spFunc.execute();
    spFunc.close();

  • CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN?

    Hi, Gurus:
    In my program, after I call 'CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.'    in the va02, user maybe do some change and save
    then I want to get those change as the dollowing:
        select single uvall into c_complete_flag from vbuk
         where vbeln = lv_vbeln.
    why I can't get the latest change.
    Thanks,

    VA02 usese the asynchronus update mehtod so, it gives you the message like "Order 1111 was saved" but the database update is still going on.
    So, you need to wait for some time before facthing the data from the database.
    You can use like:
    WAIT UP TO 10 SECONDS.
    But this statement will force you to wait for atleast 10 seconds before doing any thing.
    Regards,
    Naimesh Patel

  • Two statements, get results from the first statement?

    Ok maybe I made it sound a little harder than it is, but this is what I am trying to do. I have a result set from from a database call when I pass in the username and password . In the 1st call I get the Users info: User_ID, first_name, lastname, etc...
    But I either need to get info from the first statement, and pass it to the 2nd statement or just do two statement calls calling the same info and passing it to my user object? I dont know which if any is faster, or better. The only thing I need from the first statement is the user_id. In the 2nd statement I need the user_id to find out the user permissions.
    Here is the original code when It was getting the user info and permissions from the same table. try
               dba = new DbAccess();
               java.sql.Connection con = dba.getConnection();          
    java.sql.DriverManager.getConnection("jdbc:oracle:thin:@kares:1523:appd","user","pass");  
               ps = con.prepareStatement("SELECT USER_ID, LAST_NAME, FIRST_NAME, LOGIN, PASSWORD," +
               "X, Y, Z FROM RD_USERS WHERE LOGIN=? and PASSWORD=?");
               ps.setString(1, user);
               ps.setString(2, pass);
               rs = ps.executeQuery();
               // set the user attributes
               if ( rs.next() )
                  loginValid = true;
                  setUserId(rs.getInt("USER_ID"));
                  setLastName(rs.getString("LAST_NAME"));
                  setFirstName(rs.getString("FIRST_NAME"));
                  setLoginName(rs.getString("LOGIN"));
                  setPassword(rs.getString("PASSWORD"));   
                  X = rs.getBoolean("X");
                  setX(X);
                  Y = rs.getBoolean("Y");
                  setY(Y);
                  Z = rs.getBoolean("Z");
                  setZ(Z);
               else
                  setLastName(null);
                  setFirstName(null);
                  setLoginName(null);
                  setPassword(null);
                  setX(false);
                  setY(false);
                  setZ(false);
               rs.close(); rs = null;
               ps.close(); ps = null;
               //dba.close(); dba = null;
            } The code above gets the info from one table, I now need to get the X, Y, and Z from a different table, but I need the USER_ID first. So, the first table is set up with the user_id and user info, and the 2nd table is set up with the user_id and user permissions

    Thanks DrClap I started on the the query and I did it a little differently, but it should hopefull do the same thing. my tables are constructed as so:
    USER
         USER_ID
         FIRST_NAME
         LAST_NAME
         USER_NAME
         PASSWORD
         ETC....
    USER_PERMISSIONS
         USER_ID
         PERMISSION X
         PERMISSION Y
         PERMISSION Z
         ETC....
    My Select looks something like this
    ps = con.prepareStatement("SELECT a.USER_ID, a.LAST_NAME, a.FIRST_NAME, a.USER_NAME, a.USER_PASSWORD," +
               "b.X, b.Y, b.Z FROM RD_USERS a, RD_PERMISSIONS b WHERE USER_NAME=? and USER_PASSWORD=?");
    This is where I come to a crossroads, Can I add on another AND to say "WHERE a.USER_ID = b.USER_ID
    and do I use the =, or is it ==, or .equals(). Thanks in advance.
    orozcom

Maybe you are looking for

  • Itunes has encountered a problem and has to close.

    When I opened iTunes the first time today, I had no problem, but then I went to the store, then my computer froze, so I closed it.. And now I downloaded the update and whenever I try to open it a box pops up saying "iTunes has encountered a problem a

  • Km component portal runtime error

    hi  i am creating a simple km application to create a folder using km api when i run the application it is displaying runtime error  in the portal any help on this here is the trace . [EXCEPTION] #1#com.sapportals.portal.prt.component.PortalComponent

  • Computer screen went black after trying to adjust settings

    Hello, I prior to upgrading to win8, I was using two screens with my b320.  After upgrading I could only use the main screen.  I was trying to adjust the settings to extend the view to the second monitor when...the main monitor b320 went black.  I kn

  • Wheres the Adobe Premiere Elements 10 icon?

    I just bought Adobe Photoshop Elements 10 with Adobe Premiere Elements 10 and I have a new HP Pavillion g6, Windows 7, i5 core, 2.4 processor. The package did not have any clear instructions for installing these programs but the discs said for MAC or

  • Save and Open whole objects

    Hi, Do you know any good tutorials about saving and opening whole objects with the jFileChooser? Your direct advice on how to do it would be very appreciated too. Regards, Pingen