• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can't run MyFirstApp.java or any java file for that matter. Always 1 error.  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever i try to run MyFirstApp.java or any java file from the Command Prompt running as Administrator I get

error: cannot read: MyFirstApp.java
1 error

And its the same thing with any java app no matter the syntax. I have purposely entered mistakes into my java files and its always the same. cannot read. 1 error. Any help is appreciated because I cant move forward learning from the book Head First Java if I cant run any java files.

This is my code just in case it helps.




SOLVED
The problem was in the command prompt. The directory was the default directory and I had to point it to the folder where I save my java files.

 
Ranch Hand
Posts: 77
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to run this program from DOS command prompt ? Here is the FAQ that has many of the answers that you will need to get started.
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Before running it you need to compile it. So the steps would be "javac MyFirstApp.java" and then "java MyFirstApp".
 
David Serrano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sorry I meant I cant compile anything. I'm typing javac MyFirstApp.java.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

What sort of error message do you receive? Is it something on the lines of, “javac is not recognised as a program, command or executable file”?
 
David Serrano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was simply
1 error

But i fixed it by changing the directory in the command prompt to where the java file is saved. Which makes me think, do I really need to change the directory of the command prompt to where the java file is saved EVERY time I want to compile and run a java file?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afraid so, yes. I have my own way of doing it: look here.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to - you can provide a relative or absolute path to the source file. But then chances are that the class file ends up not in the right directory. "javac" has an option to tell it where to put the class file, but that's a complication, and the simple way to avoid that is to "cd" into the directory where the source file is.
 
David Serrano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Afraid so, yes. I have my own way of doing it: look here.


Thanks for that! I did just that. Made a folder called Javafiles right where the command prompt always starts so I'm only one simple cd away. This place is great.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Serrano wrote: . . . This place is great.
Gee Shucks! You gottus all embarrassed!

[/cowboytalk]You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!