Solved

How to call methods to a Java code

Posted on 2011-03-08
5
272 Views
Last Modified: 2012-05-11
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
Comment
Question by:Tolgar
  • 4
5 Comments
 
LVL 2

Accepted Solution

by:
chris_smith_51 earned 500 total points
ID: 35071636
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
 
LVL 2

Expert Comment

by:chris_smith_51
ID: 35071748
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
 

Author Comment

by:Tolgar
ID: 35071767
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
 
LVL 2

Expert Comment

by:chris_smith_51
ID: 35071865
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
 
LVL 2

Expert Comment

by:chris_smith_51
ID: 35071986
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now