Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of chris_smith_51
chris_smith_51

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chris_smith_51
chris_smith_51

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)
Avatar of Tolgar

ASKER

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