Results 1 to 12 of 12
  1. #1
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default Making a program.

    Hi All! Where do I begin. My first day of java(online class), I found out I have to write a program for it and it is due in a week. The teacher won't help, there is no one around me that can help. I have learned more on youtube, forums then the class I am paying for.

    I finally figured out how to install the compiler, through cmd. I tried playing around and writing the "Hello World" keep getting Error: Could not find or load main class XX.class. The code is exactly how the video showed, I even used another one and it doesn't work. I used notepad++.

    Get familiar with Java Compiler.
    Write a class that accepts a userís hourly rate of pay and the number of hours worked.
    Display the userís gross pay, the withholding tax (15% of gross pay), and the net pay
    (gross pay Ė withholding).

    That is what I have to do. Can anyone help me, link, or something on how to do this? I can't buy the book until I get my financial aid which disburses on the 8th of sept.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    How are you compiling and running the code?
    Include the directory you are running the commands (you said you used the command line I believe), and the location of the file you are compiling and running.

  3. #3
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    After I write the program on notepad++ I save it as a .java file.
    I think go to cmd.

    cd \

    the goto

    cd Test Java Stuff(thats the folder I made)

    so it will look like

    c:\Test Java Stuff>

    from there

    c:\Test Java Stuff>javac xx.java

    it will make it into a .class file

    c:\Test Java Stuff>java xx.class
    Error: Could not find or load main class xx.class

    I double checked the code. I have no clue.

    class HelloWorldApp {
    public static void main (String[] args) {
    System.out.println ("Hello World!");
    }
    }

  4. #4
    Fabken is offline Member
    Join Date
    Nov 2010
    Posts
    18
    Rep Power
    0

    Default

    Did you change your environment variables?

  5. #5
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    Yes. I am running a 64 bit version of windows should I download the 64 bit version and try that? I don't see where that would make any difference.

    Temp C:\Program Files (x86)\Java\jdk1.7.0\bin

  6. #6
    Fabken is offline Member
    Join Date
    Nov 2010
    Posts
    18
    Rep Power
    0

    Default

    Is the name of your .java file HelloWorldApp.java??

  7. #7
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    Yes it is.

  8. #8
    Joel's Avatar
    Joel is offline Member
    Join Date
    May 2011
    Location
    Placerville, CA
    Posts
    86
    Rep Power
    0

    Default

    The name of the file shouldn't have spaces (try <TestJavaStuff>) ... doesn't make a difference to the OS but for the sake of beloved Java convention let's try to hold that ground. Also, you might have to play with the environment variable on this one. Include the path of the folder where your java class is located and don't forget the semicolons ';'. at the end of the string in the name of the command you are using to try and run the program. (BTW since the file you created has SPACES in it don't forget the quote marks around the environment variable string. Silly spaces!!) After that is all done, might need a reboot. Might not work, but hey, that's engineering. Process of elimination. Good luck!
    ~MSP430 Lover~

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    :\Test Java Stuff>java xx.class
    Error: Could not find or load main class xx.class
    The java command takes the class name NOT the filename. Drop the .class

    Is xx the class name or
    class HelloWorldApp {
    is HellowWorldApp the classname?

    Look in the folder where you are trying execute the java command and see what .class files are there.
    Use the dir command to display the directory's contents.
    Last edited by Norm; 08-23-2011 at 07:09 PM.

  10. #10
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    FML, are you serious? Just drop the .class

    Bam it worked!

    Know can anyone show me what would be needed to make that program. Like a link to a site or something?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Adding to Norm's suggestions, is that your actual class code, because I suspect that shold be public class HelloWorldApp {}.

  12. #12
    Headlessmunky is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    The XX was just a variable. The class code was HelloWorldApp.class Is that what you meant? Sorry I am more of a hardware guy not a programing guy. lol

Similar Threads

  1. Making a map program
    By cchase88 in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2010, 11:01 PM
  2. Need help making program more efficient
    By cid in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 08:22 PM
  3. Making the program
    By pheonix in forum Advanced Java
    Replies: 4
    Last Post: 04-18-2009, 07:36 AM
  4. Help Making a program not crash
    By Lifeis2evil in forum New To Java
    Replies: 2
    Last Post: 12-10-2008, 04:10 AM
  5. Need help with Java classes for making a program.
    By TheDarkReverend in forum Advanced Java
    Replies: 2
    Last Post: 11-28-2008, 05:50 AM

Posting Permissions

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