Solved

How to call methods to a Java code

Posted on 2011-03-08
5
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

738 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