Solved

How to call methods to a Java code

Posted on 2011-03-08
5
273 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 50
couple of eclipse 5 36
login jsp example 24 46
eclipse apache tomcat admin console 52 95
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

805 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