Changing exception clause in method signature when overwriting a method

Hi,
I stumbled upon a situation by accident and am not really clear on the details surrounding it. A short description:
Say there is some API with interfaces Foo and Bar as follows:
public interface Foo {
   void test() throws Exception;
public interface Bar extends Foo {
   void test();
}Now, I find it strange that method test() for interface Bar does not need to define Exception in its throws clause. When I first started with Java I was using Java 1.4.2; I now use Java 1.6. I cannot remember ever reading about this before and I have been unable to find an explanation or tutorial on how (or why) this works.
Consider a more practical example:
Say there is an API that uses RMI and defines interfaces as follwows:
public interface RemoteHelper extends Remote {
   public Object select(int uid) throws RemoteException;
public interface LocalHelper extends RemoteHelper {
   public Object select(int uid);
}As per the RMI spec every method defined in a Remote interface must define RemoteException in its throws clause. The LocalHelper cannot be exported remotely (this will fail at runtime due to select() in LocalHelper not having RemoteException in its clause if I remember correctly).
However, an implementing class for LocalHelper could represent a wrapper class for RemoteHelper, like this:
public class Helper implements LocalHelper {
   private final RemoteHelper helper;
   public Helper(RemoteHelper helper) {
      this.helper = helper;
   public Object select(int id) {
      try {
         return (this.helper.select(id));
      } catch(RemoteException e) {
         // invoke app failure mechanism
}This can uncouple an app from RMI dependancy. In more practical words: consider a webapp that contains two Servlets: a "startup" servlet and an "invocation" servlet. The startup servlet does nothing (always returns Method Not Allowed, default behaviour of HttpServlet), except locate an RMI Registry upon startup and look up some object bound to it. It can then make this object accessible to other classes through whatever means (i.e. a singleton Engine class).
The invocation servlet does nothing upon startup, but simply calls some method on the previously acquired remote object. However, the invocation servlet does not need to know that the object is remote. Therefore, if the startup servlet wraps the remote object in another object (using the idea described before) then the invocation servlet is effectively removed from the RMI dependancy. The wrapper class can invoke some sort of failure mechanism upon the singleton engine (i.e. removing the remote object from memory) and optionally throw some other (optionally checked) exception (i.e. IllegalStateException) to the invocation servlet.
In this way, the invocation servlet is not bound to RMI, there can be a single point where RemoteExceptions are handled and an unchecked exception (i.e. IllegalStateException) can be handled by the Servlet API through an exception error page, displaying a "Service Unavailable" message.
Sorry for all this extensive text; I just typed out some thoughts. In short, my question is how and why can the throws clause change when overwriting a method? It's nothing I need though, except for the clarity (e.g. is this a bad practice to do?) and was more of an observation than a question.
PS: Unless I'm mistaken, this is basically called the "Adapter" or "Bridge" (not sure which one it is) pattern (or a close adaptation to it) right (where one class is written to provide access to another class where the method signature is different)?
Thanks for reading,
Yuthura

Yuthura wrote:
I know it may throw any checked exception, but I'm pretty certain that an interface that extends java.rmi.Remote must include at least java.rmi.RemoteException in its throws clause (unless the spec has changed in Java 1.5/1.6).No.
A method can always throw fewer exceptions than the one it's overriding. RMI has nothing to do with it.
See Deitel & Deilte Advanced Java 2 Platform How To Program, 1st Ed. (ISBN 0-13-089650-1), page 793 (sorry, I couldn't find the RMI spec quick enough). Quote: "Each method in a Remote interface must have a throws clause that indicates that the method can throw RemoteException".Which means that there's always a possibility of RemoteException being thrown. That's a different issue. It's not becusae the parent class can throw RE. Rather, it's because some step that will always be followed is declared to throw RE.
I later also noticed I could not add other checked exceptions, which made sense indeed. Your explanation made perfect sense now that I heard (read) it. But just to humour my curousity, has this always been possible? Yes, Java has always worked that way.
PS: The overwriting/-riding was a grammatical typo (English is not my native language), but I meant to say what you said.No problem. Minor detail. It's a common mistake, but I always try to encourage proper terminology.

Similar Messages

  • Parsing java source files - identifying method signature

    Im doing a project in which i need to parse java source file and identifying java method signature to take the methods parameters name as tokens, does anyone know how to do this with regular expression? I really appreciate your help.
    regards,
    gr33nl1nk

    i'm still working on it, but still doesn't work :'(
    // Regular expression used to find the result type and the name of a method
    //String s1 = "\\s-*\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(.*\\)";
    String s1 = "\\s-*((public|protected|private|const|abstract|synchronized|final|static|threadsafe|transient|native|volatile)\\s-+)*\\(.*\\)";
    // Regular expression used to find the method arguments
    String s2 = "([ ]*\\(.*\\)[ ]*)";
    // Regular expression used to find the method exceptions.
    String s3 = "throws[ ]+\\(.*\\)[ ]*[{;]";
    // Regular expression for white spaces separator
    String sp = "[ \t\r\n]+";
    //String mspat = s1+sp+s2;
    String mspat = s1;
    compile(mspat);

  • Deciding when to use "final" in method signatures

    Please consider this source code:
    public void foo(final Set<String> set) { ... }People who use this class don't need to know that the "set" reference is "final", right?
    Edited by: dpxqb on Apr 30, 2010 3:28 AM

    Kayaman wrote:
    They should be implicitly final so there would be no need for questions like this.I don't understand what that means.
    Or does someone here admit to having a habit of reassigning the parameters?I don't understand. I do it when it needs doing. Here is an example where I re-assigned the reference in the method signature:
    void foo(Writer w) {
      int i = 0;
      boolean hit = false;
      BufferedWriter bw = new BufferedWriter(w);
      Set<String> set = new HashSet<String>();
      bw.write(c);
      w.write(c); // no exception thrown. the object on the other end of the Writer will act weird
                  // which further masks the bug.
    }There are two working Writers going to the same location. There is no reason for this, it makes no sense, and it is a bug waiting to happen.
    This is how I got my BufferedWriter. Reassign the initial reference:
    void foo(Writer w) {
      if(! (w instanceof BufferedWriter)) {
        w = new BufferedWriter(w);
    }The only way to write is via a single object. It just prevents me from doing something stupid. I feel safer by eliminating unused references.

  • E-REC - WebDynpro Exception: Subclass of must overwrite/replace method

    Hi All,
    We are encountering an issue with an E-Recruiting web dynpro, hrrcf_a_candidate_registration, all of the sudden throwing the below error message:
    - WebDynpro Exception: Subclass of must overwrite/replace method
    Any thoughts/ideas would be helpful.
    Thanks!

    Hi Dhinesh,
    We found the following note:
    Note 1108840 - Error message when
    using browser that is not supported
    Regards,
    Nathan

  • Exceptions method signatures while extending/implementing

    Suppose If i have some throws clauses in my method signatures in an interface.Now if i define a class which implements this interfcae and while implementing i do not give the throws clause in the signature then i should expect a compilation error.Which is not the case.Can someone tell me the reason for this.

    The throws cause is not part of the method signature. It is OK for a implementing method tp promise to throw fewer exceptions (in this case none) but it would not be OK for it to threaten to throw more exceptions.
    The general model is that an implementation or override of a method must require no more and provide no less.
    Chuck

  • HT203905 I have changed my family sharing organizer payment method but when asked to add members it keeps asking for information for a card I no longer have so I do not have the security code.

    I have changed my family sharing organizer payment method but when asked to add members it keeps asking for information for a card I no longer have so I do not have the security code.  My current shows in all the correct places but when asked to verify, the old card is referenced.  I changed the card in itunes and on my phone and ipad.

    I have changed my family sharing organizer payment method but when asked to add members it keeps asking for information for a card I no longer have so I do not have the security code.  My current shows in all the correct places but when asked to verify, the old card is referenced.  I changed the card in itunes and on my phone and ipad.

  • Question about changing method signature

    Hello. I've inherited some code which contains a method with the following signature:
    foo(int x, MyObject myObject)
    Okay, so that's not really the exact signature :) In any case, I need to modify the signature to:
    foo(int x, Object myObject)
    I believe that I can do this without affecting any existing client code because Obect is a superclass of MyObject. Is that right or must I deprecate the first version and add the second separately? Whatever, happens I can't break code which was compiled against the old version. Thanks in advance.
    -jason

    That's a good point. It's probably not an issue
    however as we don't provide (supported) access to our
    implementation classes. Thanks for the input.
    -JasonThen I don't see another issue with it, as long as no other internally-written class has already overridden it and doesn't get changed at the same time. In a sense you're saying it's a "private" (not necessarily in the same sense of the private keyword) method, so you can change the implementation, including method signatures, at your whim.

  • I keep getting invalid signature when I try to downloand itunes 11.1.  I have tried to just do a download and i have tried to change internet options to accept downloads without valid signature.  but it still does not work.  anyone have suggestions?

    I keep getting invalid signature when I try to downloand itunes 11.1.  I have tried to just do a download and i have tried to change internet options to accept downloads without valid signature.  but it still does not work.  anyone have suggestions?

    I just tested it (on 10.6.8) and it worked perfectly well, so it may be something on your computer. You could try creating a new user account on your Mac and using that to try downloading. You can then install on that account and it will be available on your normal one.

  • No Method Signature - initQuery error after VO Substitution

    Hi All,
    I have done a VO Substitution for "NewBankAccountVOImpl". Below is the exact Requirement,
    iReceivables -> Query for a given Customer -> Go to accounts Tab -> Try to Pay off an invoice -> You get an option choose Payment Method as "New Bank Account" ->
    Now there are three field Routing Number, Account Number and Account Holder
    I need to restrict Account Number to minimum three characters. In 11.5.10 Oracle do not have this validation.
    So I checked out the place where the Routing Number and Account Number Validation happen i.e "NewBankAccountVOImpl" and extended the same to custom VOImpl and copied all the standard code to my custom code as below,
    package mercury.oracle.apps.ar.irec.accountDetails.pay.server;
    import oracle.apps.ar.irec.accountDetails.pay.server.NewBankAccountVOImpl;
    import oracle.apps.ar.irec.accountDetails.pay.server.NewBankAccountVORowImpl;
    import java.sql.Types;
    import java.lang.String;
    import oracle.apps.ar.irec.accountDetails.pay.utilities.PaymentUtilities;
    import oracle.apps.ar.irec.framework.IROAViewObjectImpl;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.OAException;
    import oracle.apps.fnd.framework.server.*;
    import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
    import oracle.jbo.RowIterator;
    import oracle.jbo.RowSetIterator;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OraclePreparedStatement;
    // --- File generated by Oracle Business Components for Java.
    // --------------- Modification History --------------------------
    // Date Created By Description
    // 04/01/2011 Veerendra K Account Number Validation to raise
    // error if Account Number entered is
    // less than 3 Digits
    public class MMARNewBankAccountVOImpl extends NewBankAccountVOImpl
    * This is the default constructor (do not remove)
    public MMARNewBankAccountVOImpl()
    public void initQuery()
    if(!isExecuted())
    executeQuery();
    reset();
    // Wrapper Method to validate Routing Number and Account Number
    public void validateNewBankAccount()
    OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getApplicationModule();
    RowSetIterator rowsetiterator = createRowSetIterator("iter");
    rowsetiterator.reset();
    NewBankAccountVORowImpl newbankaccountvorowimpl = (NewBankAccountVORowImpl)rowsetiterator.next();
    rowsetiterator.closeRowSetIterator();
    OAException oaexception = null;
    //object obj = null;
    int i = validateRoutingNumber(newbankaccountvorowimpl.getStrippedRoutingNumber());
    if(i == 0)
    OAException oaexception1 = new OAException("AR", "ARI_INVALID_ROUTING_NUMBER");
    if(oaexception == null)
    oaexception = oaexception1;
    else
    oaexception.setNextException(oaexception1);
    } else
    if(i == 2)
    OAException oaexception2 = new OAException("AR", "ARI_CREATE_BANK_ACCOUNT");
    if(oaexception == null)
    oaexception = oaexception2;
    else
    oaexception.setNextException(oaexception2);
    // Added by VEERENDRA KODALLI to limit addition of New Bank Account with Minimum 3 Digits
    if(validateBankAccountNumber(newbankaccountvorowimpl.getStrippedBankAccountNumber()))
    // Define Exception with FND Message MMARI_INVALID_BA_NUMBER
    OAException oaexception4 = new OAException("AR", "MMARI_INVALID_BA_NUMBER");
    if(oaexception == null)
    oaexception = oaexception4;
    else
    oaexception.setNextException(oaexception4);
    // Method to Validate if Entered Account Number and Routing Number Combination already exist
    if(validateDuplicateBankAccountNumber(newbankaccountvorowimpl.getStrippedBankAccountNumber(), newbankaccountvorowimpl.getStrippedRoutingNumber(), newbankaccountvorowimpl.getAccountHolderName()))
    OAException oaexception3 = new OAException("AR", "ARI_DUPLICATE_BA_NUMBER");
    if(oaexception == null)
    oaexception = oaexception3;
    else
    oaexception.setNextException(oaexception3);
    if(oaexception != null)
    oaexception.setApplicationModule(oaapplicationmoduleimpl);
    throw oaexception;
    } else
    return;
    // Method to Validate Routing Number
    public int validateRoutingNumber(String s)
    boolean flag = PaymentUtilities.checkDigits(s);
    if(!flag)
    return 0;
    OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getApplicationModule();
    OADBTransaction oadbtransaction = (OADBTransaction)oaapplicationmoduleimpl.getDBTransaction();
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "Start validateRoutingNumber", 2);
    String s1 = "BEGIN :1 := ARP_BANK_DIRECTORY.is_routing_number_valid(:2,:3); END;";
    OracleCallableStatement oraclecallablestatement = (OracleCallableStatement)oadbtransaction.createCallableStatement(s1, 1);
    int i = 0;
    try
    oraclecallablestatement.registerOutParameter(1, -5, 38, 38);
    oraclecallablestatement.setString(2, s);
    oraclecallablestatement.setString(3, "ABA");
    oraclecallablestatement.execute();
    i = oraclecallablestatement.getInt(1);
    catch(Exception exception1)
    exception1.printStackTrace();
    throw OAException.wrapperException(exception1);
    finally
    try
    oraclecallablestatement.close();
    catch(Exception exception2)
    throw OAException.wrapperException(exception2);
    // Debug Message
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "End validateRoutingNumber", 2);
    return i;
    // Method to Validate Duplicate Account Number
    public boolean validateDuplicateBankAccountNumber(String s, String s1, String s2)
    OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getApplicationModule();
    OADBTransaction oadbtransaction = (OADBTransaction)oaapplicationmoduleimpl.getDBTransaction();
    if(oadbtransaction.isLoggingEnabled(2))
    // Debug Message
    oadbtransaction.writeDiagnostics(this, "Start validateDuplicateBankAccountNumber", 2);
    String s3 = "BEGIN :1 := AR_IREC_PAYMENTS.is_bank_account_duplicate(:2,:3,:4); END;";
    OracleCallableStatement oraclecallablestatement = (OracleCallableStatement)oadbtransaction.createCallableStatement(s3, 1);
    boolean flag = true;
    try
    oraclecallablestatement.registerOutParameter(1, -5, 38, 38);
    oraclecallablestatement.setString(2, s);
    oraclecallablestatement.setString(3, s1);
    oraclecallablestatement.setString(4, s2);
    oraclecallablestatement.execute();
    Number number = new Number(oraclecallablestatement.getLong(1));
    if(number.equals(new Number("0")))
    flag = false;
    else
    flag = true;
    catch(Exception exception1)
    exception1.printStackTrace();
    throw OAException.wrapperException(exception1);
    finally
    try
    oraclecallablestatement.close();
    catch(Exception exception2)
    throw OAException.wrapperException(exception2);
    // Debug Message
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "End validateDuplicateBankAccountNumber", 2);
    return flag;
    public boolean validateBankAccountNumber(String s)
    OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getApplicationModule();
    OADBTransaction oadbtransaction = (OADBTransaction)oaapplicationmoduleimpl.getDBTransaction();
    // Debug Message
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "Start validateBankAccountNumber", 2);
    boolean flag = true;
    try
    // Check if the Account Number Length is less than 3 Digits
    if(s.length() < 3)
    flag = true;
    // Debug Message
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "Account Number Less than 3 Digits!", 2);
    else
    // Debug Message
    if(oadbtransaction.isLoggingEnabled(2))
    oadbtransaction.writeDiagnostics(this, "Account Number greater than 3 Digits!", 2);
    flag = false;
    //return PaymentUtilities.checkDigits(s);
    catch (Exception exception4)
    //if(oadbtransaction.isLoggingEnabled(2))
    //oadbtransaction.writeDiagnostics(this, "Entered Catch", 2);
    throw OAException.wrapperException(exception4);
    if(oadbtransaction.isLoggingEnabled(2))
    // Debug Message
    oadbtransaction.writeDiagnostics(this, "End validateBankAccountNumber", 2);
    return flag;
    public static final String RCS_ID = "$Header: NewBankAccountVOImpl.java 115.8 2008/07/21 13:49:37 nkanchan noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: NewBankAccountVOImpl.java 115.8 2008/07/21 13:49:37 nkanchan noship $", "oracle.apps.ar.irec.accountDetails.pay.server");
    I did compile the Java File and also the JPX import. It was all successful. I tested the code and it worked as expected. Now I see an exception on the page when I click the Pay button stating "No Method Signature No Method Signature - initQuery".
    The error do not come when I take out my substitution. Any one know what might be the reason for above issue. I have no idea why all of a sudden it stopped working and checked all standard filles but none got changed.
    Any pointers towards to resolve the same would be appreciable.
    Thanks in Advance,
    Veerendra

    Uma,
    try to delete all class files, recompile and run! Also, check if any CO is not extended other than from OAControllerImpl, although it would not be generally.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problems deploying application with updated method signatures on WLS8.1

    Hi,
    I have an jar file under applications which I have deployed fine on WLS 8.1 in the past. I changed the method signature on one of the EJB classes in the jar. One of the parameters now takes a different Java class type. I have recompiled everyone and repackaged the jar but when I try to deploy the jar it gives me an error because the the local interface of the EJB does not have the old Java class parameter type.
    I have checked the jar, classes in the jar, and the ejb-jar.xml and weblogic-ejb-jar.xml in the jar and it is looks fine. I have cleaned out my server deployment directories and verified the classpath in case the older jar was in there and everything looks OK. It seems for some reason 8.1 is caching the old ejb-jar.xml or somehow is remembering the old method signature and will not process the updated jar. Has anyone seen anything like this?
    Thanks for any help or recommendations

    Can you show me the error you receive?
    Another simple test would be to deploy your application to a new, empty
    server.
    You can create a new domain as easy as this:
    mkdir testDomain;
    cd testDomain;
    java weblogic.Server
    Type in the username/password that you want and answer 'Yes' when it
    asks if you want to create a new domain.
    Try deploying your jar to this new domain, and let me know if it still
    fails.
    -- Rob
    Jeff Dooley wrote:
    Hi,
    I have an jar file under applications which I have deployed fine on WLS 8.1 in the past. I changed the method signature on one of the EJB classes in the jar. One of the parameters now takes a different Java class type. I have recompiled everyone and repackaged the jar but when I try to deploy the jar it gives me an error because the the local interface of the EJB does not have the old Java class parameter type.
    I have checked the jar, classes in the jar, and the ejb-jar.xml and weblogic-ejb-jar.xml in the jar and it is looks fine. I have cleaned out my server deployment directories and verified the classpath in case the older jar was in there and everything looks OK. It seems for some reason 8.1 is caching the old ejb-jar.xml or somehow is remembering the old method signature and will not process the updated jar. Has anyone seen anything like this?
    Thanks for any help or recommendations

  • NullPointerException when mouselistener calls method

    Good Evening,
    I get a java.lang.NullPointerException when a mouselistener calls a method "populatethedatafields()" contained within the class. The populatethedatafields method tries to set the values of text fields and it is at this point the exception occurs. I have tried being more explict in identifying the fields using myclassname.this.textfieldname and this.textfieldname without success. When I moved the settext to within the mouselistener scope, I was able to make the changes.
    Why does this occur?
    I know that I can fix it by putting the settext into the listeners, but that does not seem to be good coding practice. Any suggestions for a good coding practice to solve this type of issue?
    Many thanks for your time.
    Some code removed for clarity and brevity.......
    package EMSBeta1;
    public class ContactInfoViewTEST2 extends JPanel {
    private JTextField textFieldFirstName, textFieldLastName;
    private JPanel custDetails;
    /** Creates new ContactInfoView */
    public ContactInfoViewTEST2(PowerSourceRacingModel model) {
    mod = model;
    cqm = mod.getContactQuery();
    cdt = mod.getContactDetails();
    initComponents();
    public void initComponents() {
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel detailsPanel = new JPanel();
    double size[][] =
    {{10, -1.0, -1.0, -1.0, -1.0, TableLayout.PREFERRED, 10}, // Columns
    {10, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 10}}; // Rows
    panel1.setBorder(BorderFactory.createTitledBorder("This is a title"));
    BoxLayout layout = new BoxLayout(panel1, BoxLayout.Y_AXIS);
    panel1.setLayout(layout);
    // panel2.setBorder(BorderFactory.createTitledBorder("This is a title"));
    BoxLayout layout2 = new BoxLayout(panel2, BoxLayout.X_AXIS);
    panel2.setLayout(layout2);
    detailsPanel.setBorder(BorderFactory.createTitledBorder("This is a title"));
    detailsPanel.setLayout(new TableLayout(size));
    JLabel labelLastName = new JLabel("Last Name") ;
    final JTextField textFieldLastName = new JTextField("Enter LastName",10);
    JLabel labelFirstName = new JLabel("First Name") ;
    final JTextField textFieldFirstName = new JTextField("FirstName",5);
    textFieldLastName.setNextFocusableComponent(textFieldMembershipNum);
    textFieldMembershipNum.setNextFocusableComponent(textFieldAddress);
    textFieldAddress.setNextFocusableComponent(textFieldEmerContactPhone);
    detailsPanel.add(labelLastName, "1, 1, L, C");
    detailsPanel.add(textFieldLastName, "1, 2, L, T");
    detailsPanel.add(labelFirstName, "3, 1, L, C");
    detailsPanel.add(textFieldFirstName, "3, 2, L, T");
    panel1.add(contactListPane);
    this.setLayout(new BorderLayout());
    add(panel1,BorderLayout.WEST);
    add(panel2,BorderLayout.SOUTH);
    add(detailsPanel,BorderLayout.CENTER);
    MouseListener listMouseListener = new MouseListener() {
    public void mouseClicked(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    public void mousePressed(MouseEvent e) {
    public void mouseReleased(MouseEvent e) {
    createNewContact.setEnabled(true);
    updateButton.setEnabled(true);
    insertNewDataButton.setEnabled(false);
    clearButton.setEnabled(false);
    JList theList = (JList)e.getSource();
    int indexValue = theList.getSelectedIndex();
    System.out.println("This is the selected index from the JList: " + indexValue);
    ContactIdName selectedItem = (ContactIdName)list.getSelectedValue();
    int selectedKey = selectedItem.getKey();
    contactInfo = cdt.getContactDetails(selectedKey);
    populateTheDataFields();
    list.addKeyListener(listKeyListener);
    list.addMouseListener(listMouseListener);
    public void clearFields() {
    textFieldFirstName.setText(null);
    textFieldLastName.setText(null);
    public void populateTheDataFields() {
    String first = (String)contactInfo.get("FIRSTNAME");
    String last = (String)contactInfo.get("LASTNAME");
    this.textFieldFirstName.setText(first);
    this.textFieldLastName.setText(last);
    }

    Ah Ha, Discovered the solution/problem.
    Note that I declared textFieldFirstName and textFieldLastName as class objects with private scope. Then in the initComponents METHOD, I created NEW textFieldFirstName and textFieldLastName objects whose scope is limited only to the method. By prefixing the objects with type, I was creating new instances of the objects rather than "re-using" the class objects. Class objects with appropriate scope are accessible by methods and inner classes. Objects created within a method are not unless the method returns the object.
    Subtle, but basic OO stuff that was a painful lesson. Whew!

  • Java.io.NotSerializableException when overwrite the JTable data into .txt

    hi everyone
    i had java.io.NotSerializableException: java.lang.reflect.Constructor error when overwrite the JTable data into .txt file.
    At the beginning, the code will be generate successfully and the jtable
    will be showing out with the data that been save in the studio1.txt
    previously,
    but after i edit the data at the JTable, and when i trying to click the
    save button, the error had been showing out and i cannot succeed to
    save the JTable with the latest data.
    After this error, the code can't be run again and i had to copy the studio1.txt again to let the code run 1 more time.
    I hope i can get any solution at here and this will be very useful for me.
    but i dunno how to attach my .txt file with this forum
    did anyone need the .txt file?
    the following is my suspect code
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String filename1 = "studio1.txt";
              try {
                  FileOutputStream fos = new FileOutputStream(new File(filename1));
                  ObjectOutputStream oos = new ObjectOutputStream(fos);
                   oos.writeObject(jTable2.getModel());
                   oos.flush();
                   oos.close();
                   fos.close();
              catch(IOException e) {
                   System.out.println("Problem creating table file: " + e);
                            e.printStackTrace();
                   return;
              System.out.println("JTable correctly saved to file " + filename1);
    }this is the reading code
    String filename1="studio1.txt";
            try {
                   ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename1));
                   TableModel model = (TableModel)ois.readObject();
                    jTable3.setModel(model);
                   System.out.println("reading for " + filename1);
              catch(Exception e) {
                   System.out.println("Problem reading back table from file: " + filename1);
                   return;
              }Edited by: Taufulou on Jan 8, 2009 11:43 PM
    Edited by: Taufulou on Jan 8, 2009 11:44 PM
    Edited by: Taufulou on Jan 8, 2009 11:45 PM

    is this the code u mean?
    i had put this code inside it but the problem still remain the same
    if (jTable2.isEditing()) {
                jTable2.getCellEditor().stopCellEditing();
            }i had found a new thing that when i just double click the cell without change any data inside the table
    and click the button "Save". the same exception which is
    java.io.NotSerializableException: java.lang.reflect.Constructor
    will come out again.

  • How to determine method signature

    Consider the following compilation unit in Java where ecran.afficher essentially is System.out.println. I do not understand why no error is detected at compile-time. According to me, at least the call d.m(d,c) is incorrect. There is an ambiguity between methods A.m(D, A) and D.m(A, A). But the compiler choses A.m(D, A). I cannot figure out why.
    class A
    void m(A x, A y){ ecran.afficher("A.m(A, A) -- stop") ; }
    void m(D x, A y){ ecran.afficher("A.m(D, A)") ; m(y, x) ; }
    class B extends A
              void m(A x, A y){ ecran.afficher("B.m(A, A)") ; y.m(x, x) ; }
              void m(B x, A y){ ecran.afficher("B.m(B, A)") ; y.m(x, x) ; }
              void m(A x, C y){ ecran.afficher("B.m(A, C)") ; y.m(x, x) ; }
    class C extends B
    void m(A x, A y){ ecran.afficher("C.m(A, A)") ; x.m(y, this) ; }
              void m(B x, A y){ ecran.afficher("C.m(B, A)") ; x.m(y, this) ; }
              void m(A x, C y){ ecran.afficher("C.m(A, C)") ; x.m(y, this) ; }
    class D extends A
    void m(A x, A y){ ecran.afficher("D.m(A, A) -- stop") ; }
    class Q3
    public static void main(String[] args){
    A a = new A() ; B b = new B() ; C c = new C() ; D d = new D() ;
              A w = d ; A x = b ; B y = c ; A z = c ;
              d.m(d, c) ;
              d.m(x, y) ;
              z.m(a, b) ;
              c.m(d, x) ;
              y.m(z, a) ;
    }

    Thanks for giving me the pointer to the Specification
    (third edition). Thus as far as I can
    understand it, something fundamental has changed from
    the second to the third edition. Now the class where
    the method is declared is no longer taken into
    account.
    I suppose that this change is considered acceptable
    by the Java designers since it increases the number
    of accepted programs. My program is rejected by the
    first two versions of the specification, not by the
    third one.
    I really feel it a bad idea to change such
    fundamental aspects.I disagree.
    As far as I can tell, the way the 2nd ed. is worded is a bug. I believe that the behavior you observe is what was intended all along, but that strict adherence to JLS 2nd ed. would lead to a compile time error due to ambiguity. A cannot be converted to D by method invocation conversion, so neither method matches both of the conditions.
    I could be missing something though.
    When the JLS has bugs--following it strictly leads to behavior that differs from the authors' intent--inconsistencies, or ambiguities, it must be revised. Naturally, the addition of new language features also requires revision of the spec.
    At the same times, Java becomes so complex that I
    really doubt that somebody is still able to write
    correct programs in Java (i.e., a priori, not by
    trial and error).I don't consider that a problem. Except for minimal, toy programs, I've never written a program that was perfect the first time. Nor do I need to. The compiler finds certain kinds of errors much more quickly and accurately than I ever could, and unit testing takes care of most of the rest.
    Now, if you mean that nobody is able to write reasonably bug-free code with a reasonable amount of time and effort, I disagree. But that's entirely subjective anyway.
    When I started to teach Java, I spent many days
    reading the specification (first edition) carefully.
    A few years later, I bought the second edition. But I
    found the changes so complex (the new author is
    credited as a "programming language theologist" !)
    that I almost immediately decided to stick to the
    first edition for ever.Then you have to live with the bugs and shortcomings of that editon. You also have to stick with using the corresponding version of the compiler (1.1 or whatever), or have a lang spec. that doesn't match the compiler that implements it.
    Now, looking at the cryptic description of the third
    edition, I just can say : "The world is getting
    crazy". Who could possibly understand and use that ?I don't see the problem. It took me about ten minutes of fairly intesnse concentration to understand the relevant bits. It's not Dr. Seuss, but then, it's not intended to be. A general purpose computer language that has the kinds of features Java does is inherently complex. It requires a complex spec to define it precisely and accurately.
    The problem is that I am teaching Java as a first
    programming language in my University.That's reasonable. However, I don't think that Java's goals ever included being simple enough and unchanging enough to be easily grasped in its entirety by entry level university students.
    I have to say
    to my students : This language is changing all the
    time. Yes. As are huge tracts of the technology landscape. It's the nature of the beast.
    Also my demonstration programs are behaving
    differently each year ! That sounds odd. Most of Java's changes as it moves forward have allowed programs written with earlier versions to compile and run unchanged with newer versions.
    And I am forced to use the
    latest version of the JDK, always bigger and bigger.Forced by whom? By you school's policy?
    And I hate it !At the risk of sounding condescending, if you are that resistant to change, computer science may not be the ideal field for you.
    Now what shall I do ? Since I will refuse trying to
    read and understand the third editionNow it sounds like you're pouting. "My job is too hard. I won't do it. I won't I won't I won't."
    (and the
    fourth, the fifth...), I will probably teach an
    hypothetical Java, invented by myself, and "directly
    understandable". ("Tout ce qui n'est pas direct est
    nul." (E.M. Cioran))That's your choice, I guess, but if you don't inform your students very clearly and emphatically that said language is something idealized for your convenience and doesn't reflect the real world, then you'll be doing them a great disservice (and possibly be violating Sun's license agreements or trademarks).

  • [svn:osmf:] 10996: Changing MediaElementLayoutTarget to be constructed via a static ' getInstance' method, instead of by its constructor.

    Revision: 10996
    Author:   [email protected]
    Date:     2009-10-19 07:45:26 -0700 (Mon, 19 Oct 2009)
    Log Message:
    Changing MediaElementLayoutTarget to be constructed via a static 'getInstance' method, instead of by its constructor. This prevents the construction of multiple instances that reference one single media-element. Updating client code accordingly.
    Extending layout unit tests. Adding a custom renderer, checking calculation and layout passes invokation counts.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/composition/CompositeViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/composition/ParallelViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/composition/SerialViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/gateways/RegionSprite.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/DefaultLayoutRenderer.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/LayoutContextSprite.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/LayoutRendererBase.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/MediaElementLayoutTarget.as
        osmf/trunk/framework/MediaFramework/org/osmf/utils/MediaFrameworkStrings.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/composition/TestParallelViewableTrai t.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/gateways/TestRegionSprite.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestDefaultLayoutRenderer.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestLayoutUtils.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestMediaElementLayoutTarget. as
    Added Paths:
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/composition/CustomRenderer.as

    AlexCox, can you clarify that once you get the default model out and save it in the temp var, that your ONLY access to the data is then through temp and never through the JList methods?
    Quick question for everyone: Are any of you using JList.setListData to set you initial dataset? I think that is where the bug lies. When I do not use it and start with an empty list, I am able to add to that list, and then remove from that list using the following line:
    ((DefaultListModel)myList.getModel).remove(###);
    And this cast works everytime.
    But when I start that list out with some data such as:
    myList.setListData(myStringArray);
    and then try to execute the above line, boom! I get the ClassCast exception.
    I think setListData creates a whole new model which is an inner class to JList (which seems stupid when DefaultListModel seems made for this).
    Just my thoughts on where the problem lies. I'll add my data directly to the list and see if that works better.
    PK

  • Interface method Signature...

    Hi all,
    Is there any Function Module that can be used to modify
    the signature of a method in an interface from code??
    I want to write a FM that imports the interface and
    method name and changes the method signature..
    Pls Help.
    Thanks in advance.

    Here is a sample program which will give you thep signature of the class/methods.    I'm not sure how to update them, or if it is a good idea to do so.
    report zrich_0003.
    data: l_dref  type ref to cl_abap_typedescr.
    data: l_clref  type ref to cl_abap_classdescr.
    data: x_methods type abap_methdescr.
    data: x_parameters type abap_parmdescr.
    constants: query_class type seoclsname
                        value 'CL_GUI_ALV_GRID'.
    * check if query_class exists in the current system
    call method cl_abap_classdescr=>describe_by_name
      exporting
        p_name         = query_class
      receiving
          p_descr_ref = l_dref
      exceptions
        type_not_found = 1
        others         = 2.
    if sy-subrc <> 0.
      exit.
    endif.
    l_clref ?= l_dref.
    loop at l_clref->methods into x_methods.
      write:/ x_methods-name.
      loop at x_methods-parameters into x_parameters.
        write:/     x_parameters-length,
            x_parameters-decimals,
            x_parameters-type_kind,
            x_parameters-name,
            x_parameters-parm_kind     .
      endloop.
      skip 3.
    endloop.
    Regards,
    Rich Heilman

Maybe you are looking for