Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Help with Compiling

  1. #1
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Help with Compiling

    I am new to Java and have been trying to teach myself from several books, currently "Sams Teach Yourself Java 6 in 21 Days", and I'm sadly stuck on the first day. I need to compile a simple application (and I guess a class too? I'm not sure if that needs to be compiled, but I tried anyway).

    I have two errors when I try to compile the class:
    http://i495.photobucket.com/albums/r...oboterrors.jpg

    The original code is:
    class VolcanoRobot {
        String status;
        int speed;
        float temperature;
     
       void checkTemperature() {
    	if (temperature > 660) {
    	    status = "returning home";
    	    speed = 5;
    	    }
        }
     
    	    void showAttributes() {
    	    System.out.println("Status: " = status);
    	    System.out.println("Speed: " = speed);
        	    System.out.println("Temperature: " + temperature);
        }
    }
    I also have two errors when I try to compile the application:
    http://www.mediafire.com/imgbnc.php/...bace96076g.jpg

    The original code for the application is:
    class VolcanoApplication {
        public static void main(String[] arguments) {
    	VolcanoRobot dante = new VolcanoRobot();
    	dante.status = "exploring";
    	dante.speed = 2;
    	dante.temperature = 510;
     
    	dante.showAttributes();
    	System.out.println("Increasing speed to 3.");
    	dante.speed = 3;
    	dante.showAttributes();
    	System.out.println("Changing temperatire to 670.");
    	dante.temperature = 670;
    	dante.showAttributes();
    	System.out.println("Checking the temperature.");
    	dante.checkTemperature();
    	dante.showAttributes();
        }
    }
    I'm sure the problem is rather obvious, but I'm new to programming and Java, so I don't catch the obvious yet. Any and all help is appreciated! And sorry about the image links, but I don't know how to copy straight from Command Prompt :\
    Last edited by copeg; September 9th, 2010 at 10:24 AM. Reason: Please use the code tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Compiling

    Please copy and paste here the full text of the error messages you get. Its easier to work with the data all here vs images.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Compiling

    Class code:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Wade>cd c:\documents and settings\wade\desktop\java in
    21 days projects

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>javac volcanorob
    ot.java
    volcanorobot.java:14: unexpected type
    required: variable
    found : value
    System.out.println("Status: " = status);
    ^
    volcanorobot.java:15: unexpected type
    required: variable
    found : value
    System.out.println("Speed: " = speed);
    ^
    2 errors

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>

    Application Code:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Wade>cd c:\documents and settings\wade\desktop\java in
    21 days projects

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>javac volcanoapp
    lication.java
    volcanoapplication.java:3: cannot find symbol
    symbol : class VolcanoRobot
    location: class VolcanoApplication
    VolcanoRobot dante = new VolcanoRobot();
    ^
    volcanoapplication.java:3: cannot find symbol
    symbol : class VolcanoRobot
    location: class VolcanoApplication
    VolcanoRobot dante = new VolcanoRobot();
    ^
    2 errors

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Compiling

    System.out.println("Status: " = status);
    The = makes what is in the () an assignment statement vs the concatenation of a variable to a String. The compiler complains that the String to the left of the = is a value not a variable. Normally you use a + here.

    VolcanoRobot dante = new VolcanoRobot();
    The compiler can NOT find the definition for the VolcanoRobot class. Probably because of the previous errors.

  5. The Following User Says Thank You to Norm For This Useful Post:

    w.spidey (September 9th, 2010)

  6. #5
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Compiling

    Awesome! You were right about my "=" instead of "+" error. I had that error in there twice. I guess I was rushing cuz I lost the original code and had to type it again.

    I successfully compiled the class, however, I still have the errors:

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Wade>cd c:\documents and settings\wade\desktop\java in
    21 days projects

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>javac volcanoapp
    lication.java
    volcanoapplication.java:3: cannot find symbol
    symbol : class VolcanoRobot
    location: class VolcanoApplication
    VolcanoRobot dante = new VolcanoRobot();
    ^
    volcanoapplication.java:3: cannot find symbol
    symbol : class VolcanoRobot
    location: class VolcanoApplication
    VolcanoRobot dante = new VolcanoRobot();
    ^
    2 errors

    C:\Documents and Settings\Wade\Desktop\Java in 21 days projects>



    What am I overlooking?

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Compiling

    cannot find symbol
    symbol : class VolcanoRobot
    The compiler can NOT find the definition for class VolcanoRobot.
    Where is it?

  8. #7
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Compiling

    It's in the same directory as the code I'm trying to compile, and the code I successfully compiled for the class.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Compiling

    What happens when you try to compile VolcanoRobot?
    Are either of the classes in packages?
    What is the command you use to compile the source files with? Does it set the classpath if the source files are in different packages.

  10. The Following User Says Thank You to Norm For This Useful Post:

    w.spidey (September 9th, 2010)

  11. #9
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Compiling

    Alright, I figured it out when you mentioned "classfile". I had to move the .class file to the directory set up for my environment variables. I just got it all compiled and can now move to the next steps in my book. Thanks a ton Norm!

    Sorry about all the rookie questions, but now I'm trying to launch the application, and it's not working. Am I not supposed to use Command Prompt?

    The command I use is:
    "java VolcanoApplication" (which my book instructs me to use)

    Here's the code:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Wade> cd C:\Program Files\Java\jdk1.6.0_12\lib

    C:\Program Files\Java\jdk1.6.0_12\lib>java volcanoapplication
    Exception in thread "main" java.lang.NoClassDefFoundError: volcanoapplication (w
    rong name: VolcanoApplication)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: volcanoapplication. Program will exit.

    C:\Program Files\Java\jdk1.6.0_12\lib>

    I tried using the command:
    "java VolcanoApplication.class" as well, but I get a slightly different error.

    Is there an app somewhere in the JDK that I'm supposed to use to launch programs I create?

  12. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Compiling

    Java is case sensitive. Be sure to spell the class name the same everywhere you use it.
    Try this. The class name without the extension:
    java VolcanoApplication

    I get a slightly different error
    It's important that you post all the errors. The difference can show us what the problem is.

  13. The Following User Says Thank You to Norm For This Useful Post:

    w.spidey (September 9th, 2010)

  14. #11
    Junior Member w.spidey's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Compiling

    Sweet! I launched it and it performed the way it should. The issue was that I wasn't aware Java is case-sensitive. I'll be putting that on a mental sticky note. Thanks a ton Norm! And I have no more questions for this thread

Similar Threads

  1. compiling a file
    By jkoracle23 in forum Java Theory & Questions
    Replies: 4
    Last Post: June 19th, 2010, 03:20 PM
  2. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM
  3. Declaring variables in constructor and compiling
    By Newoor in forum Object Oriented Programming
    Replies: 3
    Last Post: December 5th, 2009, 01:07 PM
  4. Strange Compiling Error
    By crism85 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 13th, 2009, 12:59 AM

Tags for this Thread