[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

How to call methods to a Java code

I am a very beginner in Java. I try to use the methods that is in another Java code. The thing that I wanna do is:

I want to call lockGeck method. This should return an object. One of the fields of this object is let's say "Area". I want to update this with the with the third input to the code. The first and the second input are first and second input to the lockGeck and saveGeck methods. The first input is an integer and the second one is a string.

THIS IS THE CODE I AM TRYING TO WRITE:

package com.mywork.tools.GeckoPrequal;

import com.mywork.tools.GeckoPrequal.ws.*;
import java.util.*;
import org.apache.commons.lang.StringUtils;


class myfirstjavaprog
{  

        public static void main(String args[])
        {
			String soapEndpointURL="http://.mywork.com/main/services/GeckWebService?wsdl";
		
			   try {
					GeckWebServiceSoapBindingStub stub = new GeckWebServiceSoapBindingStub(new java.net.URL(soapEndpointURL), new org.apache.axis.client.Service());
					
					Geck g = stub.lockGeck(Integer.parseInt(args[0]),args[1]);
					
					g.Solution += args[2];
					
				  } catch(Exception e) {
					throw new GeckoHierarchiesException(e.getMessage(), e);
				  }
            System.out.println(g);
			
			stub.saveGeck(Integer.parseInt(args[0]),args[1]);
			
        }
}

Open in new window


The Java code that I import and try to use its methods is in the attachment.


Can you please help me how to make this to run as expected?


Thanks,


GeckWebServiceSoapBindingStub.java
0
Tolgar
Asked:
Tolgar
  • 4
1 Solution
 
chris_smith_51Commented:
Hi Tolgar,

From what I understand, you want to do a simple update of the field of an object?

Well, if your Geck object field named "Area" is set to static, it should be a simple case of:

 
g.Area = args[2];

Open in new window


If not (and if you aren't sure what static really does), your best bet would be to manually create a "Setter" or "Mutator" method in the Geck class to update the field for you. For example, in class Geck, create a method such as:

 
public void setArea(String newArea) {
  this.Area = newArea;
}

Open in new window


Then, in your main method like you posted above, you would do something like:

 
g.setArea(args[2]);

Open in new window


Chris
0
 
chris_smith_51Commented:
sorry - just realised you wanted to add the value to "Area", not explicitly replace it. In which case - modify the setter method I gave you to:

 
public void setArea(String newArea) {
  this.Area = this.Area + newArea;
}

Open in new window


(I'm using strings here because you seemed to in your example - but change to integers etc. as is necessary)
0
 
TolgarAuthor Commented:
Thanks for your reply.

As far as I know "Area" or in my sample code "Solution" is static. So your first recommendation looks like the one I have in my code. The only difference is that, I want to append instead of updating the field. So I used the following:

g.Solution += args[2];

Open in new window


However, I am getting the following error message:

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[11,32] reference to String is ambiguous, both class                        com.mywork.tools.GeckoPrequal.ws.String in com.mywork.tools.GeckoPrequal.ws and class java.lang.String in java.lang match

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[13,3] reference to String is ambiguous, both class c                       om.mywork.tools.GeckoPrequal.ws.String in com.mywork.tools.GeckoPrequal.ws and class java.lang.String in java.lang match

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[18,28] reference to Integer is ambiguous, both class                        com.mywork.tools.GeckoPrequal.ws.Integer in com.mywork.tools.GeckoPrequal.ws and class java.lang.Integer in java.lang match

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[20,6] cannot find symbol
symbol  : variable Solution
location: class com.mywork.tools.GeckoPrequal.ws.Geck

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[23,15] cannot find symbol
symbol  : class GeckoHierarchiesException
location: class com.mywork.tools.GeckoPrequal.myfirstjavaprog

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[25,31] cannot find symbol
symbol  : variable g
location: class com.mywork.tools.GeckoPrequal.myfirstjavaprog

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[27,17] reference to Integer is ambiguous, both class                        com.mywork.tools.GeckoPrequal.ws.Integer in com.mywork.tools.GeckoPrequal.ws and class java.lang.Integer in java.lang match

/mywork/devel/sandbox/tolgar/workspace/prequalification/src/main/java/com/mywork/tools/GeckoPrequal/myfirstjavaprog.java:[27,3] cannot find symbol
symbol  : variable stub
location: class com.mywork.tools.GeckoPrequal.myfirstjavaprog

Open in new window



What am I doing wrong in here?

Thanks,
0
 
chris_smith_51Commented:
Hi,

The compiler is getting confused because you have two classes called "String" in your program, and it doesn't know which to use. You will have to specify which one to use whenever you instantiate a String variable (and also Integer by the looks of your error log).

So, you probably have "import x.y.String" somewhere, and in your main method for example, you are referencing a String variable - which more than likely is part of java.lang.

Thus, whenever you see "String" in your program, you probably want to replace it with "java.lang.String" and the same for Integer - unless they are characteristics which are explicit to the Geck suite you are using.

Chris
0
 
chris_smith_51Commented:
alternatively, if that is too much of an overhead (i dont know how big your class is), modify the imports to only use the ones you need from "com.mywork.tools.GeckoPrequal.ws" - instead of the whole library.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now