File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java " Watch "Java " New topic
Author

Java

rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
Hi im new to Java and every time i enter javac (file name) in cmd it comes up as a error this is the first time I put a set of codes together could anyone tell me if there a error in this code or is it just my PC as I have heard some people say.

public class CarRally {

a = JOptionPane.showInputDialog
(null, "Enter Name");
a = JOptionPane.showInputDialog

String a;
a = JOptionPane.showInputDialog
(null, "Enter M for male or F for female?");
while (!(a.equalsIgnoreCase("M")||a.equalsIgnoreCase("F")){
a = JOptionPane.showInputDialog
(null, "You must enter M or F?");
}

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Hour (0 to 23)");
int hour = integer.parseInt (a);
while (hour < 0 || hour > 23){
a = JOptionPane.ShowInputDialog
(null, "Hour wrong, please try again");
Hour = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Minutes (0 to 60)");
int minutes = integer.parseInt (a);
while (minutes < 0 || minutes > 60){
a = JOptionPane.ShowInputDialog
(null, "Minutes wrong, please try again");
minutes = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Seconds (0 to 60)");
int seconds = integer.parseInt (a);
while (seconds < 0 || seconds > 60){
a = JOptionPane.ShowInputDialog
(null, "Seconds wrong, please try again");
seconds = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Hour (0 to 23)");
int hour = integer.parseInt (a);
while (hour < 0 || hour > 23){
a = JOptionPane.ShowInputDialog
(null, "Hour wrong, please try again");
Hour = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Minutes (0 to 60)");
int minutes = integer.parseInt (a);
while (minutes < 0 || minutes > 60){
a = JOptionPane.ShowInputDialog
(null, "Minutes wrong, please try again");
minutes = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Seconds (0 to 60)");
int seconds = integer.parseInt (a);
while (seconds < 0 || seconds > 60){
a = JOptionPane.ShowInputDialog
(null, "Seconds wrong, please try again");
seconds = integer.parseInt (a);
}// end while

}// end of class
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid swaggerstar wrote:Hi im new to Java and every time i enter javac (file name) in cmd it comes up as a error this is the first time I put a set of codes together could anyone tell me if there a error in this code or is it just my PC as I have heard some people say.




Well, you definitely have tons of errors in your code... so, I agree with your compiler. I recommend that you look at the compiler errors, fix the first few, and then compile again. Don't fix them out of order -- fix the first one first. And don't do anymore than a few. The reason? There are so many weird syntax errors (such as code not in a constructor, method, or initializer), that I am sure that the compiler is completely confused after the first few.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
Thank but you have confused me more I have checked little errors and still keep saying 1error what ever I do
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid swaggerstar wrote:Thank but you have confused me more I have checked little errors and still keep saying 1error what ever I do


Care to share what this one error is?

Henry
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
this is what it previews when i enter javac CarRally


[Thumbnail for Picture1.jpg]

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

And note that you need to give your .java file name to the compiler.


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

Jeff Verdegan wrote:And note that you need to give your .java file name to the compiler.




Agreed. The code needs to be in a file with a java extension. And you need to specify the filename to the compiler.

Henry
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
i have written like that wen saving it I have selected java file to save it and it says .java will I need to input that in to cmd
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
I have found out when that when I entered javac CarryRallu by accident instead of CarRally it came up with the same error messege
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid brown wrote:I have found out when that when I entered javac CarryRallu by accident instead of CarRally it came up with the same error messege


As already mentioned, you need to specify the name of the source file -- and that includes the ".java" extension.

Henry
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
i have tried javac CarRally.Java

and it says

javac: file not found: CarRally.java
Usage: javac <options><source files>
use -help for a list of possible options
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
Thanks for your help I figured it out now came up with allot of error need to fix them now
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid brown wrote:i have tried javac CarRally.Java

and it says

javac: file not found: CarRally.java
Usage: javac <options><source files>
use -help for a list of possible options


As already mentioned, your CarRally class needs to be defined in a file named CarRally.java. The error is saying that the file does not exist. Do you have the class named in such as file?

Henry
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
I have a qeustion if an error has a > pointing upwords toward your code what does that mean
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7700
    
  20

rashid brown wrote:I have a qeustion if an error has a > pointing upwords toward your code what does that mean

It indicates, as closely as possible, the place that the compiler discovered the error.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
Thanks could you check my code and tell me on the third line were the error is as it confusing me
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
because I have tried a=JOptionPane and a = JoptionPane and the error is by the = which is confusing
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid brown wrote:Thanks could you check my code and tell me on the third line were the error is as it confusing me


Generally, it would help if you do the heavy lifting -- meaning you show use the third line and show us the exact error code.... And hint... as already mentioned, you have lots of code in invalid locations. Code needs to be in a constructor, initializer, or method.

Henry
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
as this is new to me I dont know were all the code is ment to go which is confusing me at the moment
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
every time i try change something i came up with more error then I started with
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

rashid brown wrote:as this is new to me I dont know were all the code is ment to go which is confusing me at the moment
every time i try change something i came up with more error then I started with


Then maybe you are trying too hard and too much at the same time. Start with smaller programs, always compile a line of code and make sure it runs fine before writing another statement. If you write code in such bulk, you are bound to get confused as to where the error /exception is. Anyways, can you share the line that is causing the error?


~ Mansukh
rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
better I will give that a try thank you
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

rashid brown wrote:as this is new to me I dont know were all the code is ment to go which is confusing me at the moment


Yeah. It would be a good idea to understand where code is legal -- and the legal syntax of code. Coding by trial and error is not really productive.


rashid brown wrote:every time i try change something i came up with more error then I started with


Interestingly, you can't really tell. These type of errors tend to confuse the compiler to the point that only the first few errors are correct. Also, you can probably get rid of most of these errors by throwing everything into a main() method... but ... That is not the point. Getting rid of compiler errors doesn't mean that you fixed everything.

Henry

rashid brown
Greenhorn

Joined: Apr 30, 2013
Posts: 14
I have started again and i have the last bit of code left but when insertint gender I have allowed the user inputing to select this is and the output to show with his name but there is no space how to i create a space in the output
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Surely by now, you must realize we are not mind readers. We do not have ANY idea what your code does, what it is supposed to do, why it doesn't work, or what advice to give you - because we have NO IDEA what your code looks like.

There are hundreds of different ways you could be showing a name, and for each of those, a hundred different ways it could be wrong.

I strongly suggest you read our FAQ and take to heart the advice given there.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
wood burning stoves
 
subject: Java