This is part of a lab exercise for a course I'm doing, it's not assessable, just a learning exercise. Not sure why but the tut didn't go through it, so I just went through it at home but I'm stuck on the last part.
I'm trying to write a java WSDL client to access http://www.nanonull.com/TimeService/TimeService.asmx?WSDL - I should input UTC+10 to display the current time. Below is the code that I have written:
package time;
class Client {
public static void main(String args[]){
TimeService service = new TimeService();
TimeServiceSoap port= service.getTimeServiceSoap();
String result = port.GetTimeZoneTime("UTC+10");
System.out.println("Time is "+result);
}
}
When I try and compile the code I get the following error:
C:\Program Files\Java\jdk1.6.0_22\bin>javac -d . "c:\Program Files\Java\jdk1.6.0
_22\bin\time\Client.java"
c:\Program Files\Java\jdk1.6.0_22\bin\time\Client.java:13: cannot find symbol
symbol : method GetTimeZoneTimeResponse(java.lang.String)
location: interface time.TimeServiceSoap
String result = port.GetTimeZoneTime("UTC+10");
^
1 error
Any thoughts on what I'm doing wrong?
Did you mean
String result = port.getTimeZoneTime("UTC+10");
with a lowercase g? Java method names are case-sensitive, so it won't recognize the method if you get its letter casing wrong. As per both WSDL's TimeServiceSoap documentation and Java naming conventions, method names are in camel case beginning with a lowercase letter.
What does your TimeServiceSoap look like?
Perhaps you meant to use getTimeZoneTime() (starting with a lower case letter)?
Related
i'm a new to java and just bought this amazing book to start learning with. One of the exercises, it asked me to do this ( it's exactly like in the book ) :
class SimpleDotComTestDrive {
public static void main (String[] args) {
SimpleDotComTestDrive hu = new SimpleDotComTestDrive();
int[] locations = {2,3,4};
hu.setLocationCells(locations);
String userGuess = "2";
String result = hu.checkYourself(userGuess);
String testResult = "failed";
if (result.equals("hit") ) {
testResult = "passed";
}
System.out.println(testResult);
}
}
I compiled this code on Notepad++ which compiles normally for the pass few weeks , until i compiled this code and got this error :
SimpleDotComTestDrive.java:8: error: cannot find symbol
hu.setLocationCells(locations);
^
symbol: method setLocationCells(int[])
location: variable hu of type SimpleDotCom
SimpleDotComTestDrive.java:12: error: cannot find symbol
String result = hu.checkYourself(userGuess);
^
symbol: method checkYourself(String)
location: variable hu of type SimpleDotCom
2 errors
It's pretty annoying since I've searched over the internet for the past few hours and couldn't fix it, please, if you have any idea what's wrong with this then please let me know as soon as possible, thanks in advance !!!
LOOK !!!
i know notepad++ isn't the best IDE but the book recommended me to use simple IDE for learning purposes so please, don't ask me to use other IDE, thanks !
You mentioned that hu.setLocationCells(locations); which means that there needs to be a method setLocationCells() that takes int[] as parameter. Add that method for you to work.
By the way, Notepad++ is not an IDE at all. But yes, it's right to start with this. Good luck.
The variable hu which you are trying to use is declared in the main method in SimpleDotCom class and you are trying to access it from SimpleDotComTestDrive class. So the scope of hu is limited to main method itself.
Try declaring it at the class level, either static or instance variable and try to compile the code.
The static method main, which receives an array of strings. The array should have two elements: the path where the files are located (at index 0), and the name of the files to process (at index 1). For example, if the name was “Walmart” then the program should use “Walmart.cmd” (from which it will read commands) and “Walmart.pro” (from which it will read/write products).
I don't want anyone to write the code for me because this is something I need to learn. However I've been reading this through and the wording is confusing. If someone could help me understand what it wants from me through pseudo-code or an algorithm it would be greatly appreciated.
Where I'm confused is how to initialize arg[0] and arg[1] and exactly
what they are being initialized to.
The main method's String array input argument consists of whatever String arguments you pass to the program's main method when you run the program. For example, here is a simple program that loops over args and prints a nice message with each argument's index and value on a separate line:
package com.example;
public class MainExample {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.printf("args[%d]=%s\n", i, args[i]);
}
}
}
Once you've compiled the program, you can run it on the command-line and pass it some arguments:
java -cp . com.example.MainExample eh? be sea 1 2 3 "multiple words"
Output:
args[0]=eh?
args[1]=be
args[2]=sea
args[3]=1
args[4]=2
args[5]=3
args[6]=multiple words
So lets explain to you
Create a class Inventory : if you don't know how to create a class google it just as is
The static method main: Every executable class in java (at least from the console) has the main method you should google java main method and propably in the same place you find it you will see the default arguments that it receives
When you learn about the default arguments of method main you will undertand about the 'args' that has to be on it
You will have t study the class String google it "java String class"
You will have to study the class File google it "java File class"
At the end everything else would be just logic and I beleave you have learned some at this point.
public class Inventory { // class inventory
public static void main(String[] args) // main method
{
if(args.length==2){ // check if args contains two elements
String filePath = args[0];
String fileName = args[1];
filePath+= System.getProperty("file.separator")+fileName;
File fileCMD = new File(filePath+".cmd");
//fileCMD.createNewFile();
File filePRO =new File(filePath+".pro");
//filePRO.createNewFile();
}
else {
//write the code to print the message Usage: java Inventory Incorrect number of parameters for a while and exit the program.
}
}
This is what I've understood. Basically you have to write a program to create two files, one called fileName.cmd and the other fileName.pro. You have to construct the path of the files using the arguments (input parameters of the main method) and system's file separator. If the arguments don't have two elements you have to print the 'invalid' message. That's it.
Where I'm confused is how to initialize arg[0] and arg[1] and exactly
what they are being initialized to.
You have to use command line to pass the arguments and launch the program , something like the following code in cmd or terminal:
java inventory thePath theFileName
That's how it get initialized.
This question already has answers here:
What does "Could not find or load main class" mean?
(61 answers)
Closed 9 years ago.
Im a java noob. Basically I am trying to create a program that compares two command line arguments while ignoring case and prints out the lesser of the two strings. Here is what I have so far:
public class CompareStrings
{
public static void main(String[] args)
{
String s1 = new String(args[0]);
String s2 = new String(args[1]);
if ( s1.compareToIgnoreCase(s2) > 0 )
System.out.println(s2);
else if ( s1.compareToIgnoreCase(s2) < 0 )
System.out.println(s1);
else
System.out.println("Both strings are equal.");
}
}
I keep getting the error
Error: Could not find or load main class CompareString
when I try to run it. What am I doing wrong?
"Error: Could not find or load main class CompareString"
Your error message says you couldn't load class "CompareString", but your code says your class name is CompareStrings.
Your class name is wrong.
Your error says
Error: Could not find or load main class CompareString
but the name of class is CompareStrings not CompareString
launch using java CompareStrings
Read this good tutorial on compiling and launching java programs
First of all you are trying to use wrong class, should be CompareStrings and not CompareString.
Second, I would recommend using a nice utility lib for handling command line called Cliche from Google Code site
And third, it would be good to check if the given string is null before you call compareToIgnoreCase on it
as per your error i can gues that you are running CompareString but your class is CompareStrings
So either run java CompareStrings or rename your class to CompareString
If this is the only code you have, save that file as CompareStrings.java not CompareString, and in command prompt javac CompareStrings.java. (to do this you need to configure java). then use java CompareStrings abc cbs to run this. and this will give you out put as abc
I was starting to learn Java. I followed the tutorial on how to install it.
I also checked by typing "javac"(without the quotation marks) in cmd if it works. And yes it gives a whole list of text which means its supposed to work, right?
This is my java code:
class apples{
public static void main(String args[]) {
System.out.printIn("hello youtube");
}
}
I saved it in a folder called 'test' in my c drive.
This is what I typed in cmd:
cd \
dir
now it lists everything in my c drive and one of them is test
cd test
dir
Now it lists everything in test and one of them is 'youtube.java'(the file I named), so I type
javac youtube.java
This doesn't work
This is what it gives me:
youtube.java:3: error: cannot find symbol
System.out.printIn("hello youtube");
symbol: method printIn(string)
location: variable out of type PrintStream
1 error
Can someone help me out with this?
You have a typo in your call. Change
System.out.printIn("hello youtube"); // capital 'I'
to
System.out.println("hello youtube"); // lowercase 'l'
And as has been mentioned already, in Java, the public class in a file must match the filename.
The name of the class must match the filename.
You should use
public class Youtube{
in your code(as class names are capitalized) and call the file Youtube.java.
Also you used In instead of ln.
Use:
System.out.println(
which means "print line to System.out".
I am brand new to Java. I am having an issue compiling a basic java program, and I am trying to understand why. (note that the TextIO class in the code is used in book I am studying to simplify the IO process, I don't believe that is where the issue is) Here is my code:
public class ProcessSales {
public static void main(String[] args) {
String ln;
String tmp;
int i;
int noval;
TextIO.readFile("sales.dat");
while (TextIO.eof() == false){
ln = TextIO.getln();
for (i = 0; i < ln.length(); i++) {
if (ln.charAt(i) == ':'){
tmp = ln.subString(i + 1);
}
} // end line for loop
try {
System.out.printf("%8.2f\n", Double(tmp.trim()));
}
catch (NumberFormatException e) {
noval++;
}
} // end of file while loop
System.out.printf("\nThere were a total of %d cities that didnt have data\n", noval);
} // end of main subroutine
} // end of ProcessSales class
The compile error I get is as follows:
[seldon#PrimeRadiant Exercises]$ javac ProcessSales.java
ProcessSales.java:15: cannot find symbol
symbol : method subString(int)
location: class java.lang.String
tmp = ln.subString(i + 1);
^
ProcessSales.java:20: cannot find symbol
symbol : method Double(java.lang.String)
location: class ProcessSales
System.out.printf("%8.2f\n", Double(tmp.trim()));
^
2 errors
Ive declared ln as a String object. The subString method is straight out of the java api for a String object. I'm not understanding why I'm getting a cannot find symbol compile error, especially if it lists the method signature and location right below the error.
I marked the questions as homework, since I am working out of a textbook, and I am looking to understand the issue, rather than a flat solution. However it is self study, and not part of any actual class (right now).
The great thing about the Java compiler is, it gives you alot of information to use in determining where problems exist in your code. For you, the first problem is here:
tmp = ln.subString(i + 1);
In this case you capitalized a letter that you shouldn't have. It should be:
tmp = ln.substring(i + 1);
Whenever you see compiler output saying 'cannot find symbol' its because the Java compiler could not find a method matching the outputted name, either due to a syntax error or missing dependency. For your second problem, you didn't post the appropriate code, but from the error message I can see you are missing the new keyword.
System.out.printf("%8.2f\n", Double(tmp.trim()));
Should be
System.out.printf("%8.2f\n", new Double(tmp.trim()));
If this is not your first programming language then I would recommend using an IDE like Eclipse, as it will give you auto-completion and syntax checking. It's a great tool for quickly learning the API's for the language. However if Java is your first programming language please do continue without hand-holding, as the hard knocks will cement in the lessons learned, faster.
I haven't verified any of this, I just looked at the source and the error messages.
The first error seems to be a case error. The Java String class does not have a subString method, it has a substring method, note the lowercase s. Reference
The second error would probably be resolved if you used new Double or Double.valueof instead of Double. This is because you are probably trying to construct a new Double object and using new operator or the valueof method in the Double class do this for you. Reference
In Java, method names are case sensitive. Check back with the String API specification for the correct "casing".
Regarding your first error, you have a typo. It should be ln.substring(i+1) not ln.subString(i+1). All source code text in Java is case sensitive.
Regarding your second error, you need to use the new keyword to instantiate the Double object. Without new, the compiler is not looking for the constructor; instead it is looking for a method Double within your ProcessSales class and cannot find it.