Superclass variable not calling subclass method
hi,
i've got a bit of a problem with my method invocation. i'll try to explain in abstract terms:
class SuperClass {
void method(int x){
//some action
class SubClass extends SuperClass {
static final int VARIABLE = 1;
void method(int x){
x = modify(x);
super.method(x)
int modify(int x){
return x += VARIABLE;
my problem is that i've got about 20 or so subclasses that i refer to through a superclass reference. as i understand it, i should be about to call:
int result = superClassRef.method(5);
and this will call the subclass method, perform the modification and return the result. my problem is twofold.
1) the superclass reference dosen't call the subclass's method
2) what happens when it gets to the subclass's modify method and trys to access the subclass's VARIABLE through a superclass reference? as i understand it shouldn't be accessible from the superclass reference.
hmmm...any help would be most appreciated.
cameron
that was what i ment -
SuperClass superClassRef = new SubClass();
superClassRef.method(5); //dosen't return anything
i think this may be turning into a more wide ranging application problem. i tried to bypass the natural superclass method invocation with the following code:
Method m = superClassRef.getClass().getMethod("method");
m.invoke(superClassRef, new Object[]{new Integer(x)});
but on trying this it throws an InvocationTargetException.
for clarity - the two methods in the subclass are:
void method(int x) (overrides the superclass's method(int x))
and
int modify(int x)
sorry for the bad naming.
i've figured out the variable thing - i'd only be if there were variable shaddowing in the subclass that problems could arrise.
Similar Messages
-
A superclass reference can call subclass method directly?
A Swing Container reference seems to be able to call the methods of subclass directly. For example, you can find following expression in a JApple or JFrame implementation:
Container c = getContentPane()
But if you look at the standard API site, you find that Container doesn't have getContentPane(), nor its superclass. Its subclass, JApplet or JFrame has the method! That means that a reference of superclass can use the method in subclass directly. It's hard to understand since superclass can't aware what in its subclasses. Inheritance got to be one direction-->from superclass to subclass.
Thanks for advise.Hey yylx,
I dont see in you example where a superclass is calling the a function of its subclass. An object can call any of its own function, any protected or public functions of its superclass, and can also invoke any public functions of objects it has references to.
So in JFrame, when it calls getContentpane() it is invoking one of its own functions which is fine. The function returns a reference to a Container, which JFrame can now invoke the public functions of... The public interface of an object, in this case a container, is available to any other object. So JFrame can call any functions on that particular Container.
Does that clarify? If not, explain further....
Josh -
ABAP Proxy Inbound message does not call generated method
Hi,
we tried to generate a ABAP Proxy for a customer demo. It just should retrieve some data and write them to a database table.
the generation and activation of the proxy was without errors. If we call the check function the method works fine.
But if we receive data from XI via the regarding interface it looks as if the execute-method of the generated class is not called. We can see the message in SXMB_Moni, but nothing is written to the db table.
Does someone have any idea?Hi Peter,
There will be some error in the Proxy Side.
Check this in Transaction Code-SXMB_MONI of Application System(R/3 etc) not in the XI system.
There may be some communication(http etc) issues.
Also check this -
/people/krishna.moorthyp/blog/2005/12/23/monitoring-for-processed-xml-messages-in-abap-proxy
Hope this helps to findout what is the error.
Regards,
Moorthy -
Use a variable to call a method
Hi
I'm not very familiar with JAVA. I'm just doing different things in my free time at home.
Now I try to write a abstract class so my mostly used methods are allways the same. but for that I have to call a method in a class but I know the method only at runtime.
e.g.
String[] methods = {"compare", "compareIgnoreCase"};
// Here I like to call the method out of the above string:
result = callMethod(class, methods[0], param1, param2);Is this possible in Java? If yes, how?
By the way, I have J2SE 1.5 installed. And I'm working with NetBeans as my developing tool.
Thanks for any help
Cheers
mobaClasses can be dynamically loaded to invoke their methods using Java Reflection feature.
The article http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html provides examples on using the reflection feature.
In particular, the section "Invoking Methods by Name" in the article gives an example of invoking a method dynamically.
The relevant APIs (in java.lang and java.lang.reflect packages) are documented at:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-summary.html
and http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html. -
CommandButton does not call action method ?
Hi BalusC or JSF gurus,
I have a requirement to build a database table and update the row in the database table followed with save.
I used this from posts : http://balusc.xs4all.nl/srv/dev-jep-dat.html.
It was very excellent. Thanks BalusC.
table.jsp:
<h:dataTable rows="0" value="#{LCCircuitUtil.circuitList}" var="currentRow" binding="#{LCCircuitUtil.dataTable}">
<h:column>
<f:facet name="header">
<h:outputText value="Circuit Name"/>
</f:facet>
<h:commandLink action="#{LCCircuitUtil.editLinkAction}">
<h:outputText value="#{currentRow.circuitId}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Audit Comments"/>
</f:facet>
<h:commandLink action="#{LCCircuitUtil.editLinkAction}">
<h:outputText value="#{currentRow.auditComment}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Start Date"/>
</f:facet>
<h:commandLink action="#{LCCircuitUtil.editLinkAction}">
<h:outputText value="#{currentRow.startDate}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="End Date"/>
</f:facet>
<h:commandLink action="#{LCCircuitUtil.editLinkAction}">
<h:outputText value="#{currentRow.endDate}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status "/>
</f:facet>
<h:commandLink action="#{LCCircuitUtil.editLinkAction}">
<h:outputText value="#{currentRow.status}"/>
</h:commandLink>
</h:column>
</h:dataTable>
<h:commandButton value="New" action="#{LCCircuitUtil.newButtonAction}"/>
</h:panelGroup>
Upon click the link or newButtonAction i am able to see the edit.jsp with the populated row values..
<h:form id="EditCircuitForm">
<h:panelGrid columns="2">
<h:outputLabel value="CIRCUIT ID" rendered="#{LCCircuitUtil.circuitTO.circuitId > 0}"/>
<h:outputLabel value="#{LCCircuitUtil.circuitTO.circuitId}" rendered="#{LCCircuitUtil.circuitTO.circuitId > 0}"/>
<h:outputLabel value="Audit Comment"/>
<h:inputText value="#{LCCircuitUtil.circuitTO.auditComment}"/>
<h:outputLabel value="Start Date"/>
<h:inputText value="#{LCCircuitUtil.circuitTO.startDate}"/>
<h:outputLabel value="End Date"/>
<h:inputText value="#{LCCircuitUtil.circuitTO.endDate}"/>
<h:outputLabel value="Status"/>
<h:inputText value="#{LCCircuitUtil.circuitTO.status}"/>
</h:panelGrid>
<h:commandButton value="Save" action="#{LCCircuitUtil.saveAction}"/>
<h:commandButton value="Cancel" action="return" immediate="true"/>
<h:inputHidden value="#{LCCircuitUtil.circuitTO.circuitId}"/>
</h:form>
Save Action in LCCircuitUtil.java
public String saveAction()
System.out.println("saveAction ");
this.updateCircuit(circuitTO);
System.out.println("End saveAction");
return "return";
Issue : I am not able to call saveAction from the edit.jsp..It does not call the save Action in the backhand Managed Bean
Thanks,
bkhi balusC,
I have not set any validation criteria anywhere(may be later)..
<h:panelGrid columns="2">
<h:outputLabel value="CIRCUIT ID" rendered="#{LCCircuitUtil.circuitTO.circuitId > 0}"/>
<h:outputLabel value="#{LCCircuitUtil.circuitTO.circuitId}" rendered="#{LCCircuitUtil.circuitTO.circuitId > 0}"/>
<h:outputLabel value="Audit Comment"/>
<h:inputText id="ip1" value="#{LCCircuitUtil.circuitTO.auditComment}"/>
<h:outputLabel value="Start Date"/>
<h:inputText id="ip2" value="#{LCCircuitUtil.circuitTO.startDate}"/>
<h:outputLabel value="End Date"/>
<h:inputText id="ip3" value="#{LCCircuitUtil.circuitTO.endDate}"/>
<h:outputLabel value="Status"/>
<h:inputText id="ip4" value="#{LCCircuitUtil.circuitTO.status}"/>
<h:message for="ip1" /><br>
<h:message for="ip2" /><br>
<h:message for="ip3" /><br>
<h:message for="ip4" /><br>
</h:panelGrid>
I didn't receive any error messages..When i save it refreshes the same page.
Thank you,
bk
Message was edited by:
kbalas78 -
Calling subclass/method in a parentclass
class A extends Frame implements ActionListener
Button ok;
public void actionPerformed (ActionEvent ae)
try
if (ae.getActionCommand().equalsIgnoreCase("OK"))
/* HOW DO I CALL CLASS B OR METHOD IN CLASS B ONCLICK OK BUTTON*/
catch(Exception e)
System.out.println(e);
class B extends A
B()
//create a panel and will show some buttons, textfield etc.
public static void main(String args[])
new A();
}Is it so hard to click on the Formatting Help link, that I provided earlier AND that is at the top of the screen where you post the question?
Is it so hard to ask your question OUTSIDE of the unformatted code, so as to make it easier to find?
That aside:
HOW DO I CALL CLASS B OR METHOD IN CLASS B ONCLICK OK BUTTON
You can't. What you CAN do is make your super class abstract, with an abstract method, make your subclass a concrete implementation:
public abstract class A extends Frame implements ActionListener
protected Button ok;
public void actionPerformed (ActionEvent ae)
try
if (ae.getActionCommand().equalsIgnoreCase("OK"))
doOKCommand();
catch(Exception e) /*Catch specific exeptions, much better than the general excpetion */
e.prinbtStackTrace(); /* get much better info this way... */
protected abstract void doOKCommand();
public static void main(String[] args)
A anA = new B(); //Note, use new B() to get B functionality!!!
} //end of class A
public class B extends A
B()
//create a panel and will show some buttons, textfield etc.
protected doOKCommand()
//Do real Stuff
} -
UIX : Data action doesnt call a method
hi,
1)I have created two uix pages u1 and u2
2)I have created a data action(a1) based on method(findinvoices)
3)I have created farward from u1 to data action(a1)
4)I have created another farward from data action(a1) to u2
5)I method to accept the params which i defined in u1 and execute the method which i draged and dropped on action(a1)
Note i have defined the param values for each param of data action(a1).
Why data action(a1) is not calling the method instead it directly goest to u2 and execute the query on it.
Thanks.Hi Shay,
I have one problem because how can I create a JSP Page to display Method Results in JDeveloper10.1.3???
I already created another page and tried to Drag and Drop my Method from Data Control Palette, but I only have the choice to create a button and I would like to see the result.
Adding a c:out tag to the JSP page.
Can you help me with this problem??
Thanks,
Micaela -
ADF VO Row Fetch Range Issue: Action is not called after 10th row
Hi People!
I am working with an Application here in which one page has a table based on a view object. This table has range navigation, and the VO configuration for Tuning is to fetch rows in batches of 1000, all in one fetch. Now, i have a single selection configured in this table, and also a button on the <tableActions> facet which calls a method on the backing bean.
The problem is, for the first 10 rows of this table, the method is called (seen through the debugger), but when we move the selection to the 11th row or further, the page only refreshes but does not call the method.
This is not a problem with the data, because we tried two other approaches:
1) removed the range navigation and shown all the records in the same page: the error persists for the 11th row ahead
2) changed the VO query to return only the 11th row from the previous test using its ID: the action is called, now that the row is the first on the rowset.
Have you experienced similar behavior? Why the Action is not executed when the selected row comes after the tenth row?
Any help is greatly appreciated!
Regards
Thiago SouzaHi Frank, thanks for the reply.
I have assembled a step-by-step based on the HR schema. For this example, i have created an EmployeesVO based on the EMPLOYEES table, and an App Module to provide a data control. From then on:
1) Create a JSF JSP to list the Employees VO
1.1) Bind the JSF Page to a Backing bean
1.2) Create an af:page element on the page
2) Drag the EmployeesVO from the Data Control Palette to the af:page
2.1) Read-Only Table, Selection Enabled
2.2) Do not include table navigation.
3) Double-Click the automatically created submit button on the TableSelectOne section
3.1) Bind it to a method on the Backing Bean
3.2) Add some code to it, in my case i tested:
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Teste"));
4) Run the example and try two approaches:
4.1) select one of the first ten rows and click on the button: The action is fired.
4.2) select the eleventh row and click on the button: The action is not fired.
4.3) select one of the first ten rows again and click on the button: The action is fired.
This example didn't even include range navigation, but if you want to test you will see the result is the same.
Please let me know if you want further info.
Thanks a lot!
Thiago Souza -
Calling native methods in a package
Hi!
We have a problem when calling native methods in a class which is in a package. As you can see from the code below we have a class making an instance of a class<testBando> which makes a instance of another class<Bando> which contains the native methods. When running the program we get the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: initialize
at test2.Bando.initialize(Native Method)
at test.testBando.<init>(testBando.java:10)
at Main.main(Main.java:5)
When we take the class that calls the native methods out of any package every thing works fine! Can you not call native methods inside a package or what are we doing wrong?
// testBando.java
package test;
import test2.*;
public class testBando {
Bando b;
public testBando() {
b = new Bando();
b.initialize();
// Bando.java
package test2;
public class Bando {
public native void initialize();
static {
System.loadLibrary("bando");
// Main.java
import test.*;
public class Main {
public static void main(String[] args) {
new testBando();I suspect that your problem is that you have not
regenerated the signature when you placed the native
method's object in a package. Or same result but different sourc:
-package name was changed and it wasn't regen'd
-javah was run incorrectly (which gens the signatures with no package name.) -
Invoke a subclass method via Superclass reference variable.
Hello,
I need to invoke 'subclass' methods from a superclass reference variable as each subclass has a different
methods and behaviour.
My query is
In the Main, when I invoke product.getProductType(),I get a reference back to the Product.
I need a reference to the subclass object so that I can invoke methods of that subclass.
How can I get the required subclass type and invoke methods specific to the subclass?
Is my design incorrect?
abstract class Product {
public abstract Product getProductType();
class Bond extends Product{
@Override
public Bond getProductType(){
return this;
// Methods specific to Bond
public String getBondIssuer(){
public Long getBondFaceValue(){
class Option extends Product {
@Override
public Option getProductType(){
return this;
// Methods specific to Options
class Main {
public static void main(String args[]){
Product product = new Bond();
product.getProductType(); // Here I get get a reference back to Product.
// What I need is a reference to the subclass type (Bond) so that I can invoke Bond methods
}If your client already knows it has a Bond it should just use that as a reference. If you have general handling functions or classes, you can make them generic so that even if you give them a Product they can return the specific sub class.
Simplest example:
Bond james = doSomethingWithAProduct(new Bond());
public <T extends Product> T doSomethingWithAProduct(T product) {
return product;
} -
How to call a subclass method.
Hi:
I am trying to call a method from the subclass. I get many errors. Please correct the following code.
public abstract class A{
private int id;
public static void main(){
A obj = new B(200);
obj.subclassMethod;
class B extends A{
public void subclassMethod(){
System.out.println("ID is : " +id);
public B(int i){
id = i;The first problem:
A obj = new B(200); // This is perfect
obj.subclassMethod; // <--obj is an object of type "A" and "A" doesnt know "subclassMethod()"
so in order to call "subclassMethod" you have to make a explicit casting to "B".
((B)obj).subclassMethod(); //remeber that calling a method needs "()"
The second problem:
System.out.println("ID is : " +id);You cannot acces a private variable or function from anywhere else but the class.
If you want to acces you need to declare it:
protected: for access from anywhere in the package and/or subclass(for your case i recomend this).
public: for acces from anywhere.
(nothing)package:(dont declare anything) acces for anywhere from the class.
In resume:
Change to the following lines to fix:
private int id; // --> protected int id;
obj.subclassMethod; // --> ((B)obj).subclassMethod();I hope this help.
N�stor Mata. -
Calling the subclass method.
How to call the method of a sub class which is redefined in the subclass.
1. The super class also has the implementation.
2.No separate instance method is created for the sub class(which creates
instance) .
3.There is a method s_instance of the super class which is static.
4.Therefore the s_instance cannot be redefined.Hi,
static methods are called using classname=>method_name. There are no instances for static methods. so CALL METHOD super_class=>s_instance...
I do not understand how a method can have the name s_instance ?!
Regards,
Clemens -
Operation not found error while calling AM methods from managed bean
Hi,
operation not found error while calling AM methods from managed bean.
written a method with two parameters in AM.
exposed the method in AM client interface
in the page bindings added the method in method action ..left empty in the value fields of the parameters.
calling the method from managed bean like below
String userNameVal = (String)userName.getValue();
String passwordVal = (String)password.getValue();
OperationBinding operationBinding =
ADFUtils.findOperation("verifyLogin");
operationBinding.getParamsMap().put("userName",userNameVal);
operationBinding.getParamsMap().put("password",passwordVal);
operationBinding.execute();
i am getting operation verifyLogin not found error.Please suggest me something to do.
Thanks
SatyaHi vlsn,
Can you try with the below code
// in your backing bean
OperationBinding operation = bindings.getOperationBinding("verifyLogin");
//Put your both parameters here
operation.getParamsMap().put("parameter_name1", parameterValue1);
operation.getParamsMap().put("parameter_name2", parameterValue2);
operation.execute();
if (operation.getResult() != null) {
Boolean result = (Boolean) operation.getResult();
and share the result.
regards,
Rajan -
Calling a method from another class... that requires variables?
I'm calling a method from another class to change the date (its a date object) in another class.
I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
My code is:
public int changeDate()
cycleDate.setDate();
}I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
Any ideas! :Df1d wrote:
I'm calling a method from another class to change the date (its a date object) in another class.
I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
My code is:
public int changeDate()
cycleDate.setDate();
}I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
but I'm not sure how!
setDate(16, 6, 2008);
I have tried, but then I get errors such as ')' expected?
Any ideas! :Dyou need to post your code if you're getting specific errors like that.
but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
i.e. syntax error -
The pdfs that I produce in Word are very large. I need a method of compressing them variably - not just a quick reduction using the quartz filter. Is their a suitable free compression programme,
PDF Shrink for Mac
Compress PDF – Reduce your PDF Online
PdfCompress for Mac
Maybe you are looking for
-
Macbook Pro to AVR receiver.
Hi, I connected my laptop with a mini DVi to HDMI converter, then HDMI cable. I get both video and sound. The sound, however, is a second or so slower when I play movies/DVDs. Sound is fine elsewhere (ex. youtube). Any ideas on why this is so? T
-
Printing line beginning aligment problem in dot-matrix printer
in smart-forms i have two windows with same upper-margin and there is 10 mm space between them. i print both of them a text which two rows but in right window begining of text is sliding right , second row of second window begins one or two columns s
-
I'm not an app developer, but I'm wondering if there is an app that enable's USB devices connected via the camera USB and using the most current iOS 5.0 to use USB devices that draw on the iPad's power. I'm making reference to some USB microphones su
-
My Windows Adobe Reader gives an Error on Download of update
My Windows XP gives me an error everytime I try to download the Update it has happened about ten times now I have tried to delete Adobe but it will not finish delete. Thanks.
-
I can't download itunes 10.6.3 on my mac
i can't download itunes 10.6.3 on my mac and the apple site shows itunes 10.7 but my OS version is 10.5.8 so 10.7 itunes wont be compatible right?