Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Error

Status
Not open for further replies.

sliptdisk

Programmer
Aug 16, 2000
115
US
I'm just getting started and attempted to compile the HelloWorldApp.java, but, got a message saying it couldn't be read. So, I typed, simply, javac HelloWorldApp (w/o the .java extension), and, now, it's saying I have an

javac:invalid argument: HelloWorldApp, then
Usage:javac: <options> <source files>
where possible options include:

followed by a laundry list. Can anyone help figure out what's going wrong, please?
 
javac HelloWorldApp.java
is the proper way to compile it.

To run the program

java HelloWorldApp

If you already tried this, then post more details about the error message and the class.


[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
I'm getting:

error: cannot read: HelloWorldApp.java

When I enter &quot;java HelloWorldApp&quot;, I get:

exception in thread &quot;main&quot; java.lang.NoClassDefFoundError:
HelloWorldApp

Does that tell you anything?

Dan [sig][/sig]
 
Did it compile successfully, ie do you have HelloWorldApp.class in the same directory as HelloWorldApp.java? If not then it is not being compiled.

also remember that in java the name of the file is cAsE sensitive.

public HelloWorldApp
{
//some stuff
}

The file that you would save the above code would be HelloWorldApp.java

Take a look at the class name in the file and make sure it matches the name of the file.

Also, post the code so we can take a look at it....


[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Ok. Here's the code:

/**
* The HelloWorldApp class implements an application that
* simply displays &quot;Hello World!&quot; to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println(&quot;Hello World!&quot;); //Display the string.
}
}


Now, something unusual happened. I did a search for HelloWorldApp.java on my C drive and found nothing. Searched HelloWorldApp.*, and, it found the two text files I had saved, with the .java extension. I don't see a .class file in there. I searched for one, but, there doesn't seem to be one, so, no, it's not compiling. What gives? [sig][/sig]
 
What O/S are you using? [sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Sily question, when you try to compile your program
javac HelloWorldApp.java are you in the same directory as the program?

you could also try typing the full path when you are compiling javac c:\java\HelloWorldApp.java and see if this helps.

Also, check to see if your classpath is setup properly. you should have something like:
CLASSPATH = .;c:\java\lib\;
in your autoexec.bat.
the &quot;.&quot; tells the compiler and java to look in the current directory first, the second part tells java to look in &quot;c:\java\lib&quot;. I usually put packages and stuff in that directory.

To see if you have a CLASSPATH variable setup, type set at the command prompt. If you do have a CLASSPATH setup please post it.


[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
I don't see a CLASSPATH listed anywhere, when I type in &quot;set&quot;, then Enter. I thought I was having some kind of trouble with the autoexec.bat, when I was setting the jdk2 up, but, I wasn't sure. At any %, according to the instructions, I'm supposed to change directories (cd java), so, I'm doing that first. The path I'm showing is C:\WINDOWS;C\WINDOWS\COMMAND;C\WP51\;C\JDK1.3\BIN. This seems to be pointing to the Word Perfect directory, but, I don't know what to do about it. I tried your suggestion about the full directory path, but, it resulted in the same error. [sig][/sig]
 
All the PATH variable does is basically allow you to type java anywhere in your directory structure. That is, if you type a command, windows will search the directories that are specified in the PATH. In your PATH variable, the rest of the stuff is irrelavent to java, just the c:\jdk1.3\bin.

You need to set a CLASSPATH variable in your autoexec.bat.

Open your autoexec.bat and type the following underneath the line that contains your PATH:

PATH = blah blah blah
CLASSPATH = .;c:\jdk1.3
Once you are finished, save it and restart your machine.
Then try recompiling the HelloWorldApp.java.

I know how frustrating this can be, I have been there myself!

Keep us posted....
[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Ok. Well, forgive me for asking, but, how do I open my autoexec.bat? [sig][/sig]
 
at a command prompt type &quot;edit c:\autoexec.bat&quot; without the quotes.....Hope this helps.... [sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Well, shoot. I don't know what to do, now. I tried everything that you've told me, and, still get the read error. I did a search and couldn't find &quot;HelloWorldApp.java&quot;, but, did find &quot;HelloWorldApp.java.txt&quot; I unhid the extension file names, but, still can't get the thing to save without the txt extension, even though I changed the filetype to AllFiles. This is very confusing and frustrating. Can anyone help me?

Dan [sig][/sig]
 
Are you using notepad to save your java programs?? If so when you save it you have to use this syntax &quot;HelloWorld.java&quot; put that in exactely in the filename feild, with the &quot;&quot;, the &quot;&quot; tells notepad to save it as a .java file not as HelloWorld.java.txt. Then try to compile it :) Either that or take your existing file and go to dos and type in
ren HelloWorld.txt.java HelloWorld.java

good luck

[sig]<p>ackka<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"Do No Harm, Leave No Tracks"<br>
ICMP Summer 2000, 2600 Article<br>
<br>
[/sig]
 
Thanks for the tip. I opened the text file and saved it as &quot;HelloWorldApp.java&quot; with the quotes, opened the DOS window, typed cd java, then javac HelloWorldApp.java, but, am still getting the error message. If you have any other ideas, I'm all ears (well, eyes, I guess). Thanks.

Dan [sig][/sig]
 
Maybe you should try to go step by step through the whole thing:

[red]
1. You download(ed) jdk1.2.2 or jdk1.3 from sun. (I have 1.2.2 so I'll explain this with that one)

2. After downloading you usually get a setup.exe file on your desktop which you double-click on and which installs the jdk.

3. Usually it is installed in c:\jdk1.2.2 (or c:\jdk1.3 if you have that one)

4. At this point you could set up a system-wide path to run the java compiler from anywhere in the system as explained above. However, since you're having trouble just getting something to compile, just forget about that for the moment.

5. If everything above is true then javac.exe (the java compiler) should be in c:\jdk1.2.2\bin

6. Therefore the easiest way to get your program to compile is to put it in that directory. So put HelloWorldApp.java there. (in c:\jdk1.2.2\bin)

7. Now open a DOS prompt.

8. Go to that directory (you'll probably be in the desktop initially so type cd ..\jdk1.2.2\bin)

9. Now that you are in the bin directory and your java program is also in the bin directory you should be able to compile it by typing:

javac HelloWorldApp.java

10. If that doesn't work then your jdk may have problems or there could be something wrong with the file.
[/red]
I honestly don't mean to sound condescending by explaining all this. However, often a little detail missed along the way can screw everything up.

Hope this helps. Post again if you are stil having problems. [sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Well, both, the app and the .exe file were in the bin folder, but, after all is said and done, I'm still getting the error, so, I'm going to try and find an uninstall file, and, re-download the whole schmear (that's the jdk1.3 schmear, by the way), and, give it another go before I'm suddenly possessed to go do strange things to my dog with a fork. [sig][/sig]
 
I don't find an uninstall mechanism, anywhere. Is it going to behove me to just reinstall jdk (and, for that matter, is there any reason why I might prefer to get 1.2?), should I just delete the entire contents of the jdk folder, then install, or what? I know that my inexperience is holding me back, here, of course, so, don't worry about sounding like you're talking down to me. Considering how much attention to detail is necessary for this, I want to make sure I get it right.

Dan [sig][/sig]
 
You can try going into the settings -> add/remove programs then see if its in there. On my computer, I believe it's listed there as:

Java 2 SDK Standard Edition v1.2.2

But I've reinstalled the jdk before by just deleting the folder (jdk1.2.2) on the hard-drive then running the new setup program and haven't had any problems. You should save anything that you put in there of course first.

By the way, which error are you &quot;still getting&quot;?


[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
The error that I'm getting reads &quot;error Hello World App
cannot read. 1 error.&quot; or something very close to that. Incidentally, at this point, I have just uninstalled what appeared to be corrupted files in the jdk environment. I will be redownloading, tonight, and, will keep you abreast of what happens. Thanks for everything, everybody.

Dan [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top