Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Really simple answer probably...  RSS feed

 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm really just starting to learn java and I am trying to compile my first
little bit of source code.
when I give the command 'javac Party.java'
I always get an error in return saying 'error: cannot read: Party.java'
I tried editing the source code in wordpad and in notepad and tried saving it in different formats but nothing seems to work.
Please help!

PS: Forgive me if my English is broken or just plain wrong as it is not my mother tongue.
 
gunasekhar arvind
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Check the name of the class that you have used in your file.Java is case-sensitive. So party and Party are not the same.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to life with the JDK and the javac compiler.

Common problems?

everything is case sensitive: if the java file is Party.java, the class declaration must be:

public class Party

not

public class party or partY or parTy

Also, make sure your editor doesn't append a .txt to the extesion of your class file.

Here is a multimedia flash video that goes through all the steps for compiling Java code:

http://www.technicalfacilitation.com/examscam/get.php?link=../scja/tutorials

Look at the link: write compile and run, run, run.


Good luck dude. It'll be somethign very simple. It's frustrating, but it's worth it.

-Cameron
 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick replies.
About being case sensitive, I had already paid attention to it so that wasn't the problem.
And the link to the flash tutorial only runs for 11s so I didn't get any further.
Any other suggestions?
 
gunasekhar arvind
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible for you to post the code that you have used in your file?
Also it would be helpful if you can provide information regarding how and from where you are trying to compile the file.
 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;

import java.awt.event.*;

class Party{

public void buildInvite(){
Frame f = new Frame();
Label l = new Label("Party at P-J's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} // more code here...
}


I finally got it compiled (simply gave the entire path to the file, stupid I didn't try that before!), but now I don't seem to be able to run the Party.class

If it is of any help I'm doing the very first example from 'Head first Java: second edition' (p.3)

:roll:
 
gunasekhar arvind
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the JVM is not able to find your class file.So for your problem go to the directory where your class file is present. Then type this command java -cp . <filename>
[ September 07, 2006: Message edited by: gunasekhar arvind ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kids --

Listen: when someone new to Java has a problem compiling and running their first class, please be extra careful in the answers you give. Giving wrong or misleading answers can be extremely frustrating.

For the compiling problem, all the answers about case sensitivity, etc, were clearly inappropriate: the compiler message says that the compiler can't find the file, and that means one thing and one thing only: there's no file "Party.java" in the current directory. On Windows, both party.java and Party.java would work fine at this point as far as getting past this message. I'm glad the OP was able to figure out the solution by himself, although it would have been nice if someone had helped him. Telling him to "cd" into the directory where the source code exists before compiling would have been a good idea too.

For the second part (running the class) we've got one answer so far and it's flat out wrong. You do not provide the name of a *.java file, or the name of any file, as an argument to the "java" program; you provide the name of a class. You may also need to specify where the class is, but you don't and can't do it by adding the path to the argument the way you would with the "javac" program.

Anyway, assuming that there's now a file in the current directory named "Party.class", then you can run your program with

java -cp . Party

That's "java space dash cp space dot space Party". Note there's no file extension here. The argument is the name of a class, not the name of the file.

If "Party.class" is in some other directory besides the current one, then use "cd" to change to that other directory before trying this command.
 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to everyone for the quick replies.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!