Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Is something wrong with my code?

 
Greenhorn
Posts: 9
1
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot get this to compile, I am not sure why. I have JDK 8 installed and the correct path set to the environment variables. When I try to compile, with "java HelloMe.java" I get an error, "Error: Could not find or load main class HelloMe.java". This is for a school assignment. I am new to this. thanks if you can help me. Here is the snippet of code, is it written correctly? am I missing something? thanks again for viewing.

 
Marshal
Posts: 72595
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain how you compiled that code. Did you get any other error messages? It is only possible to use java XYZ.java in (I think) Java10+, not Java8. You need to run the compiler program first:-
javac XYZ.java
java XYZ
 
Campbell Ritchie
Marshal
Posts: 72595
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class should be called HelloMe, not HelloMe.java (line 12).
 
Jay Rem
Greenhorn
Posts: 9
1
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Please explain how you compiled that code. Did you get any other error messages? It is only possible to use java XYZ.java in (I think) Java10+, not Java8. You need to run the compiler program first:-
javac XYZ.java
java XYZ


I compiled it with "java Hello.Me.java", and I tried "javac Hello.Me.java". When I use javac: 'javac' is not recognized as an internal or external command, when I use java: "error could not find or load main class HelloMe.java.
operable program or batch file.
 
Jay Rem
Greenhorn
Posts: 9
1
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The class should be called HelloMe, not HelloMe.java (line 12).


Thanks for that, I actually had recently changed it as a trial and error process and never changed it back. I have used both with and without .java, Ill remove it and keep trying. Thanks.
 
Saloon Keeper
Posts: 8061
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Type
It should tell you the current version of the compiler you are using, or give you an error message. If you get an error then there's something wrong with your JDK installation.
 
Carey Brown
Saloon Keeper
Posts: 8061
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should not be "Hello.Me", should be "HelloMe".
 
Carey Brown
Saloon Keeper
Posts: 8061
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On line 38, remove:
Scanner guidelines:
  • Only ONE Scanner created from System.in should be opened for the *ENTIRE* program.
  • THE Scanner created from System.in should never be closed.
  •  
    Jay Rem
    Greenhorn
    Posts: 9
    1
    Eclipse IDE Python Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Carey Brown wrote:Type
    It should tell you the current version of the compiler you are using, or give you an error message. If you get an error then there's something wrong with your JDK installation.


    here is my version of jdk.
     
    Jay Rem
    Greenhorn
    Posts: 9
    1
    Eclipse IDE Python Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I appreciate the help I have gotten this far, it still will not run. I will reach out to my professor and ask for help. I have done all the suggestions and cannot get it yet. I am hopeful though.
     
    Saloon Keeper
    Posts: 12864
    279
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Post the latest version of your code, the command you're using to build it, and the error message you're getting.
     
    Carey Brown
    Saloon Keeper
    Posts: 8061
    70
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Also, what directory is the java file in and what directory are you in when you type the javac command?
     
    Saloon Keeper
    Posts: 23508
    161
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Please don't edit your code samples. It confuses people. If you change your code, post the updated code in the message thread.

    I've reverted your changes. Although as far as I can tell, they were minor and only related to email addresses, it's better, as I said, to post the latest code separately.

    Welcome to the Ranch, by the way!
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic