Results 1 to 10 of 10
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post What Could be Wrong with This code????

    I created 2 classes
    Java Code:
    class VolacanoRobot {
    	String status;
    	int speed;
    	float temperature;
    
    	void checkTemperature() {
    		if (temperature > 660) {
    			status = "returning home";
    			speed = 5;
    		}
    		if (temperature >= 800) {
    			status = "ROBOT DESTROYED";
    		}
    	}
    	void showAttributes() {
    		System.out.println("Status : " +status);
    		System.out.println("Speed : " + speed);
    		System.out.println("Temperature : " +temperature);
    		}
    	}
    Second class is
    Java Code:
    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 Temperature to 670.");
    		dante.temperature = 670;
    		dante.showAttributes();
    		System.out.println(" Checking Temperature ");
    		dante.checkTemperature();
    		dante.showAttributes();
    
    		System.out.println(" Changing Temperature to 870.");
    		dante.temperature = 870;
    		System.out.println(" Checking Temperature ");
    		dante.checkTemperature();
    		dante.showAttributes();
    	}
    }
    On compiling, i get Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\JAVA J21Work\pfe>cd C:\JAVA J21Work\J21Work\VolcanoRobot

    C:\JAVA J21Work\J21Work\VolcanoRobot>javac VolcanoApplication.java
    VolcanoApplication.java:3: cannot access VolcanoRobot
    bad class file: .\VolcanoRobot.java
    file does not contain class VolcanoRobot
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
    VolcanoRobot dante = new VolcanoRobot();
    ^
    1 error

    What could be the source of this error??

    Thanks in advance
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    Is VolancoRobot public?

    in the same package, two separate classes.

    Java Code:
    public class VolcanoRobot {
    	String status;
    	int speed;
    	float temperature;
    
    	void checkTemperature() {
    		if (temperature > 660) {
    			status = "returning home";
    			speed = 5;
    		}
    		if (temperature >= 800) {
    			status = "ROBOT DESTROYED";
    		}
    	}
    	void showAttributes() {
    		System.out.println("Status : " +status);
    		System.out.println("Speed : " + speed);
    		System.out.println("Temperature : " +temperature);
    		}
    	}
    Java Code:
    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 Temperature to 670.");
    		dante.temperature = 670;
    		dante.showAttributes();
    		System.out.println(" Checking Temperature ");
    		dante.checkTemperature();
    		dante.showAttributes();
    
    		System.out.println(" Changing Temperature to 870.");
    		dante.temperature = 870;
    		System.out.println(" Checking Temperature ");
    		dante.checkTemperature();
    		dante.showAttributes();
    	}
    }
    output:
    Java Code:
    Status : exploring
    Speed : 2
    Temperature : 510.0
     Increasing speed to 3.
    Status : exploring
    Speed : 3
    Temperature : 510.0
     Changing Temperature to 670.
    Status : exploring
    Speed : 3
    Temperature : 670.0
     Checking Temperature 
    Status : returning home
    Speed : 5
    Temperature : 670.0
     Changing Temperature to 870.
     Checking Temperature 
    Status : ROBOT DESTROYED
    Speed : 5
    Temperature : 870.0
    Last edited by Sno; 08-19-2010 at 04:26 PM.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Thumbs up

    Thanks Sno . Realised it was a typo
    The class is supposed to be VolcanoRobot.class and not VolacanoRobot.class

    Cheerz!!
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  4. #4
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    on second note, there's a way to have two classes in one .java class correct!?
    Do you know how to do this Manfizy?
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default

    bad class file: .\VolcanoRobot.java
    file does not contain class VolcanoRobot
    This is really weird. The error message implies a program is looking at a .java file expecting it to be a class file?

    Can anyone explain how this happens?

  6. #6
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    could a possible rename of the program?

    Java Code:
    C:\JAVA J21Work\J21Work\VolcanoRobot>javac VolcanoApplication.java
    VolcanoApplication.java:3: cannot access VolcanoRobot
    bad class file: .\[B]VolcanoRobot.java[/B]
    file does not contain class VolcanoRobot
    but he had

    class VolacanoRobot {
    ....
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default

    Inside class name doesn't match filename! Made test pgms and get the above error.
    Last edited by Norm; 08-19-2010 at 07:15 PM.

  8. #8
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Thumbs up

    Quote Originally Posted by Sno View Post
    on second note, there's a way to have two classes in one .java class correct!?
    Do you know how to do this Manfizy?
    @Sno, i have no idea so how do i make it happen???

    cheerz!!
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default

    Your terminology leads to confusion. There are source files and byte code files.
    The source files have extension .java. The byte code files have extension .class
    The source files can contain more than one class definition, but only one of them can be public and its name should match the source filename.
    I think there can only be one class file definition in a .class file.

  10. #10
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Thumbs up

    Quote Originally Posted by Norm View Post
    Your terminology leads to confusion. There are source files and byte code files.
    The source files have extension .java. The byte code files have extension .class
    The source files can contain more than one class definition, but only one of them can be public and its name should match the source filename.
    I think there can only be one class file definition in a .class file.
    I think what Sno was trying to say is that there is a way to combine two source files with a .java extension into one file with a .java extension.
    Correct me if am wrong!!!
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

Similar Threads

  1. Please tell me what i am doing wrong in this code
    By Basit781 in forum CLDC and MIDP
    Replies: 11
    Last Post: 05-20-2010, 05:08 PM
  2. What is wrong with my code?!
    By new2java2009 in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 08:01 PM
  3. Need help! something wrong in my code
    By novak100 in forum New To Java
    Replies: 2
    Last Post: 11-18-2009, 11:59 PM
  4. what's wrong with my code? please help me...
    By lovely23 in forum Java Applets
    Replies: 2
    Last Post: 03-01-2009, 01:33 PM
  5. What's wrong with this code?
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 11-29-2008, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •