Page 1 of 3 123 LastLast
Results 1 to 20 of 42
Like Tree2Likes

Thread: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

  1. #1
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Exclamation NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    • I make a new project named "Java".
    • I make a new package named "Java".
    • I make a new class named "display".
    • I type in code:
      Java Code:
      package Java;
      public class display {
           public static void main (String[] args){
                System.out.println("Does this work?");
           }
      }
    • I run the program.
    • Results in:
      run:
      Error: Could not find or load main class Java.display
      Java Result: 1
      BUILD SUCCESSFUL (total time: 0 seconds)


    Could someone please help me troubleshoot?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    762
    Rep Power
    13

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Hello,

    One thing that I can think of is whether you saved your file in the correct folder and filename. Because your package is Java and your class name is display your Java class file should be located in a directory called Java and file name display.java. Please check that.

  3. #3
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Yes, I can find it.
    C:\Users\Iy13n\Documents\Netbeans Projects\Java\src\Java\display.java
    I still don't see what I'm doing wrong.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Can you also find a file named display.class i that directory? (or maybe its in ../bin/display.class, I don't know how NetBeans organizes its projects).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    NetBeans would place the compiled file in C:\Users\Iy13n\Documents\Netbeans Projects\Java\build\classes\Java\display.class

    Note that it's not a good idea to try to use a package name Java / java / javax etc.

    Also learn the Code Conventions for the Java Programming Language: Contents

    db
    Last edited by DarrylBurke; 09-09-2014 at 10:08 PM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Also, package names should be lower case and class names should be CamelCase with a leading capital.
    You seem to have that in reverse.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Ok, so I created a new package and class with the names newpackage and NewClass, respectively.
    I can see the file named NewClass.class in the directory.
    Then I added the previous code to it and edited it to fit the package and class
    But when I try to run to run it, it still says the same thing, the error message.
    So that didn't work.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Quote Originally Posted by Iy13n View Post
    But when I try to run to run it
    Be specific -- how, exactly, did you 'try to run it'?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Include the directory you were in when you ran the command, and the exact command you ran.
    And whether you did javac before it.
    And the full error message (even if it's the same as in your first post).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Ok, so I ran it using Shift+F6.
    The directory was C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\classes\newpackage\NewClass.cl ass
    It didn't work, and the error message was:
    Error: Could not find or load main class newpackage.NewClass
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    And Tolls, what do you mean by javac?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Just in case you were doing stuff on the command line.
    It has happened, where we thought someone was trying to execute via the IDE but turned out they were only using the IDE to write the code, and ran from the CLI.

    Have you tried a Clean and Build?
    Netbeans might have got its knickers in a twist.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Ok, so I used Clean and Build.
    This is what happened:
    ant -f "C:\\Users\\Iy13n\\Documents\\NetBeans Projects\\Java" -Dnb.internal.action.name=rebuild clean jar
    init:
    deps-clean:
    Updating property file: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\built-clean.properties
    Deleting directory C:\Users\Iy13n\Documents\NetBeans Projects\Java\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build
    Updating property file: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\built-jar.properties
    Created dir: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\classes
    Created dir: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\empty
    Created dir: C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\generated-sources\ap-source-output
    Compiling 2 source files to C:\Users\Iy13n\Documents\NetBeans Projects\Java\build\classes
    compile:
    Created dir: C:\Users\Iy13n\Documents\NetBeans Projects\Java\dist
    Copying 1 file to C:\Users\Iy13n\Documents\NetBeans Projects\Java\build
    Nothing to copy.
    Building jar: C:\Users\Iy13n\Documents\NetBeans Projects\Java\dist\Java.jar
    To run this application from the command line without Ant, try:
    java -jar "C:\Users\Iy13n\Documents\NetBeans Projects\Java\dist\Java.jar"
    jar:
    BUILD SUCCESSFUL (total time: 1 second)

    So I think that failed.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    That seems to imply that there isn't anything in the project.
    Have a look int he generated jar file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    So the generated file is C:\Users\Iy13n\Documents\NetBeans Projects\Java\dist\Java.jar, right?
    I see the Java.jar file, but I can't seem to run it.
    Also, there is a README text file in the same folder.
    So...

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,995
    Rep Power
    32

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Moved to the IDE section.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Quote Originally Posted by Iy13n View Post
    So the generated file is C:\Users\Iy13n\Documents\NetBeans Projects\Java\dist\Java.jar, right?
    I see the Java.jar file, but I can't seem to run it.
    Also, there is a README text file in the same folder.
    So...
    Open the jar file up.
    If you're on windows (to be honest this also works in Linux) just open it and (unless it's executable) it should show you the contents.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Its best to just have a proper compression tool installed like 7zip and directly open up the jar in that.
    Tolls likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  18. #18
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    I tried both your ways, it doesn't open.
    If I click on the file, the it says: "Error: unable to access jarfile."

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,995
    Rep Power
    32

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    Can you open a command prompt window, change to the folder with the jar file and enter the command:
    java -jar THEJARFILENAMEHERE.jar

    Copy the full contents of the command prompt window and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Iy13n is offline Noob
    Join Date
    Sep 2014
    Location
    Illinois
    Posts
    16
    Rep Power
    0

    Default Re: NetBeans IDE 8.0 - Error: Could not find or load main class Java.display

    "Change to the folder?"

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 10-29-2013, 08:00 PM
  2. Error: Could not find or load main class
    By iSamir in forum New To Java
    Replies: 16
    Last Post: 06-25-2013, 05:39 AM
  3. Replies: 7
    Last Post: 01-01-2012, 12:29 PM
  4. Replies: 3
    Last Post: 12-09-2011, 03:51 AM
  5. Error: Could not find or load main class Ops.java
    By Javasubbu in forum New To Java
    Replies: 4
    Last Post: 10-05-2011, 10:52 PM

Tags for this Thread

Posting Permissions

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