my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Problem compiling java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem compiling java class" Watch "Problem compiling java class" New topic
Author

Problem compiling java class

Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
I'm having trouble finding java on a macosx thru terminal. i can't recall what i typed on Terminal but i got this message "Could not create the Java virtual machine." could anyone tell by that whether or not my mac includes java sdk? Thanks

Miric
[ September 25, 2004: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

As far as I know, Java comes pre-installed. I always install the developer tools so I'm not 100% sure it's in the base pacvage (but I'm pretty sure it is).

It doesn;t sound like Java is missing, but more like that something is preventing the JVM from starting properly. What that might be I do not know.

Have you visited the Apple Support site and searched for this issue?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
A virtual machine comes preinstalled; the JDK does not, but comes with the developer tools.
Gaurav Mac Mathur
Ranch Hand

Joined: Feb 19, 2002
Posts: 47
AFAK
OSX come with JDK installes.
if java -version is not workign means u are log in as wrong user or soemthing.
chack out /System/Library/Frameworks/JavaVM.framework/Versions/
for current version of Java been used.

Latest update available is Java 1.4.2_05
or what is commonly known as
Java 1.4.2.Update 1
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
thank you all. it seems to be found.

although, i have been trying to test one programming that prints messages to the screen prompting the user for her name and her "lucky number', but it doesn't seem to compile and it says that the code has errors which i am sure that it's all correct. Also I am wondering maybe there are specific java commands for mac? is there anything i'm missing below?





[ September 25, 2004: Message edited by: Miric ]

[ September 25, 2004: Message edited by: Miric ]
[ September 25, 2004: Message edited by: Miric ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

"Miric",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

Also I am wondering maybe there are specific java commands for mac?


Nope. Java is Java, even on the Mac.

It appears that the cs1 package is not in your compilation classpath.

Since your problem is no longer Mac-specific, I'm moving this along to the Java in General(beginner) forum.

I'll also change the title as appropriate.
[ September 25, 2004: Message edited by: Bear Bibeault ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
As Bear pointed out, you're having a CLASSPATH problem. The class cs1.Keyboard being used by your program must be locatable through the CLASSPATH, but it isn't. I'd guess this class was provided by your instructor, or it came with the materials you're studying.

As I mentioned, this class must be locatable through the CLASSPATH. For example, if you put it in the /java folder (which would mean that the class file Keyboard.class would be in /java/cs1), then the following commands should work for compiling and running your Lucky program.

javac -classpath .:/java Lucky.java
java -classpath .:/java Lucky

(On a Windows machine, those colons would be semicolons.)

If this cs1.Keyboard class is something that you'll be using a lot, or if there are other classes that are part of this cs1 package, you might want to edit your operating system CLASSPATH environment variable in a more permanent manner, so that you don't have to always type -classpath .:/java when compiling and running Java programs. For instructions on how to do that, I recommend taking a look at our FAQ on how to set the CLASSPATH. I believe the section on Linux also applies to the Mac OS.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
Dirk Schreckmann,

i'm sorry if it may seem a silly question to you, but where do i get cs1 in order to locate for example in java folder?

i followed the link "our FAQ on how to set the CLASSPATH" but i'm having a hard time to understand what it's saying.

If you are using bash as your command shell, open .bash_profile in your favorite text editor. You should already have one in your home directory. If not, you can create it. If use another shell (i.e. ksh, csh, etc.), they run similar profile scripts when loging in. I don't know what the file names are for these other shells, though. If all else fails, you should be able to use .profile instead, which is usually executed no matter which shell you use. For my text editor, I like emacs, so the command line looks something like this:


emacs .bash_profile

The syntax is similar to the autoexec.bat file in Windows 9x/ME. Add something similar to the following lines to the .bash_profile file:


CLASSPATH=.:/usr/local/fubar/Foo.jar:/home/johndoe/myclasses
export CLASSPATH


when i create .bash_profile thru emacs, then there is a new file window and i put the following "CLASSPATH=.:...". then how can i complie to create a class cs1.Keyboard?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Do you have the source code for cs1.Keyboard? Is this something you're supposed to create as part of your assignment? Did your instructor give you a cs1.Keyboard class? Is it something from your learning materials that is perhaps downloadable from a website?
[ September 28, 2004: Message edited by: Dirk Schreckmann ]
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
How to compile cs1.Keyboard ?

Example on Windows OS.

source code in c:/src
class file in c:/classes

Code in c:/src/cs1/Keyboard.java

Compile cs1.Keyboard.java
1. cd c:/src/cs1
2. set p=c:/classes
3. set CLASSPATH=.;%p%;%CLASSPATH%
4. javac -d %p% Keyboard.java
5. Keyboard.class should be created in c:/classes/cs1 directory


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
Originally posted by Dirk Schreckmann:
Do you have the source code for cs1.Keyboard? Is this something you're supposed to create as part of your assignment? Did your instructor give you a cs1.Keyboard class? Is it something from your learning materials that is perhaps downloadable from a website?

[ September 28, 2004: Message edited by: Dirk Schreckmann ]


Yes, i do need that class as it is part of my assignment at my
university. There is an assingment i have to do is Add.java and in it
actually java.text.DecimalFormat and cs1.Keyboard needs to be imported
before writing it. The description of this simple program is that it
prompts you twice to enter any number and gives you a total. Do you
think THIS class is downloadable from a website? if so could you suggest any?
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
Originally posted by somkiat puisungnoen:
How to compile cs1.Keyboard ?

Example on Windows OS.

source code in c:/src
class file in c:/classes

Code in c:/src/cs1/Keyboard.java

Compile cs1.Keyboard.java
1. cd c:/src/cs1
2. set p=c:/classes
3. set CLASSPATH=.;%p%;%CLASSPATH%
4. javac -d %p% Keyboard.java
5. Keyboard.class should be created in c:/classes/cs1 directory


i followed compiling 1, 2 but on third a message came out such as this:



Am i again missing something on this process?
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
on Unix/Linux OS MUST use

$CLASSPATH or $p replace %CLASSPATH% or %p%

and replace " ; " with " : "
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
Originally posted by somkiat puisungnoen:
on Unix/Linux OS MUST use

$CLASSPATH or $p replace %CLASSPATH% or %p%

and replace " ; " with " : "


it worked, thanks to you. but i apologize with another question, could you also tell me why it still says that the Keyboard class doens't exist when i complie the Lucky program? if this class needs to be located in java folder then i located it, however it's not doing the job.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Put c:/classes/cs1 in classpath.


Groovy
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
it worked, thanks to you. but i apologize with another question, could you also tell me why it still says that the Keyboard class doens't exist when i complie the Lucky program? if this class needs to be located in java folder then i located it, however it's not doing the job.


before compile Lucky.java , please check Keyboard.class in your clases directory.

For more information to solve problem, please post your step and message error.
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
Couldn't open the jar launcher.

the error message:

"The jar file "Keyboard.class" couldn't be launched. Check the Console for possible error messages"

:roll:
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Originally posted by Miric Ubaydov:
Couldn't open the jar launcher.

the error message:

"The jar file "Keyboard.class" couldn't be launched. Check the Console for possible error messages"

:roll:


Jar file? From where is jar coming here? I hope that you are using java and not jar to execute java file.
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
i'm using mac platform and i don't know why it launches with jar.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
First java with MAC
Miric Ubaydov
Greenhorn

Joined: Sep 24, 2004
Posts: 11
If im not mssing anything else i have tried every option to compile a java program with cs1.Keyboard class. I copied this class into every java folders even into the directory where i saved the program.. alas NO success.

if anyone had this classpath problem before with Mac, i would appreiciate so much if you could share it here.

Miric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem compiling java class
 
Similar Threads
Problem compiling java class
Cannot create stub
Java 1.5 on mac
WA #1.....word association
Jar file accessing folder