1

I'm following a very simple/basic tutorial that uses NetBeans. I installed it in my ubuntu 20.04.2 LTS via sudo apt install netbeans and just started a new project with the "create new main class" checkbox marked. However, whenever I try to run my code I get the "javaapplication5.JavaApplication5 class wasn't found in JavaApplication5 project. The code I'm trying to run is a simple "Hello world":

package javaapplication5;
   
public class JavaApplication5 {

    public static void main(String[] args) {
        System.out.print("Hello world!");
    }
}

I also tried right-clicking the project, selecting run, and selecting the class I want, but the class doesn't even show up. What am I doing wrong here?

enter image description here

Edit: here is the message displayed in the output after i try to build the project:

ant -f /home/marco/NetBeansProjects/JavaApplication6 - 
Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: 
/home/marco/NetBeansProjects/JavaApplication6/build/built- 
clean.properties
Deleting directory /home/marco/NetBeansProjects/JavaApplication6/build
clean:
init:
deps-jar:
Created dir: /home/marco/NetBeansProjects/JavaApplication6/build
Updating property file: 
/home/marco/NetBeansProjects/JavaApplication6/build/built- 
jar.properties
Created dir: 
/home/marco/NetBeansProjects/JavaApplication6/build/classes
Created dir: /home/marco/NetBeansProjects/JavaApplication6/build/empty
Created dir: 
/home/marco/NetBeansProjects/JavaApplication6/build/generated- 
sources/ap-source-output
Compiling 1 source file to 
/home/marco/NetBeansProjects/JavaApplication6/build/classes
compile:
Created dir: /home/marco/NetBeansProjects/JavaApplication6/dist
Copying 1 file to /home/marco/NetBeansProjects/JavaApplication6/build
Building jar: 
/home/marco/NetBeansProjects/JavaApplication6/dist/JavaApplication6.jar
To run this application from the command line without Ant, try:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java -cp 
/home/marco/NetBeansProjects/JavaApplication6/dist/JavaApplication6.jar 
javaapplication6.JavaApplication6
deploy:
jar:
BUILD SUCCESSFUL (total time: 1 second)

I have managed to create a main class and compile the project by using apache netbeans instead of the netbeans i installed via sudo apt install. I have no idea what is the difference between the two of them, though.

Edit: as asked below, the jdk version i get via java --version is:

openjdk 11.0.10 2021-01-19 OpenJDK Runtime Environment (build
11.0.10+9-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

and my defective netbeans is Apache Netbeans IDE 10.0

  • Try selecting "Clean and Build" from the menu, then run again. Your code is fine, it's just an issue with NetBeans. – markspace Apr 05 '21 at 17:59
  • What happens if you build the project? – Simon Martinelli Apr 05 '21 at 18:00
  • @SimonMartinelli when i click build or clean and build, nothing happens. Then when i run the code again, it pops up the same window saying there is no main class found. – Marco Antnio Barra Montevechi Apr 05 '21 at 18:12
  • How did you create the project? – Simon Martinelli Apr 05 '21 at 18:18
  • Also try right clicking on the text of the source file, and pick "Run File...". That should work and will give us some clues if it doesn't. – markspace Apr 05 '21 at 18:21
  • 1
    @SimonMartinelli i clicked in File->New Project selected the Category Java, the Java Application Project->Next (the "Create Main Class" checkbox was already marked) -> Finish. Knowing my computer and myself, i would bet its an installation problem. Is there any chance that this is caused by wrong installation proccess? – Marco Antnio Barra Montevechi Apr 05 '21 at 18:23
  • @markspace doing so generated a window with the message 'Class "javaapplication5.JavaApplication5" does not have a main method.' Also, something curious i noted is that in the video tutorial that i am following, the text editor colours the "out" in "System.out.print" while my editor doesnt modify the font or anything, as if it didnt recognize it as a important word – Marco Antnio Barra Montevechi Apr 05 '21 at 18:26
  • Maybe you should start over https://www.bouraspage.com/repository/articles-java/creating-a-new-java-project-in-netbeans-ide#:~:text=Start%20the%20NetBeans%20IDE%2C%20and,as%20shown%20in%20Figure%201.&text=The%20%E2%80%9CNew%20Project%E2%80%9D%20wizard%20will,as%20shown%20in%20Figure%202. – Simon Martinelli Apr 05 '21 at 18:47
  • If all else fails you can try [clearing the NetBeans cache](https://stackoverflow.com/a/65570256/12567365). – andrewJames Apr 05 '21 at 19:57
  • You might be using a JDK that is not supported, so update your question to state the version of Java and NetBeans. Note that JDK 14 is the most recent version supported by NetBeans 12, so you cannot use Java 15 or Java 16. Those releases came out after NetBeans 12. – skomisa Apr 07 '21 at 01:44
  • @markspace _"...it's just an issue with NetBeans"_ is a bold claim, but very unlikely to be true. NetBeans is far from perfect, but it is highly unlikely that is not possible to create and run a trivial "Hello World" project if NetBeans and Java are installed and configured correctly. – skomisa Apr 07 '21 at 01:54
  • "Installed and configured correctly" is what I had in mind. Yes if the OP did everything right, it would have worked. But I think it's likely that is not the case. "Issue with NetBeans" means the OP likely made some mistake somewhere, but not with the code. That's all I'm saying. – markspace Apr 07 '21 at 02:19
  • Please update your question with the exact versions for Java and NetBeans. Without that your question is unanswerable - all we can do is speculate, and make guesses about the cause. – skomisa Apr 08 '21 at 19:13
  • @skomisa Done! The JDK version is 11.0.10 and the netbeans is 10.0. – Marco Antnio Barra Montevechi Apr 12 '21 at 13:25
  • @MarcoAntnioBarraMontevechi OK. Please also update your question to link to the _"very simple/basic tutorial that uses NetBeans"_ that you were following. This helps others attempt to reproduce your problem. – skomisa Apr 12 '21 at 17:49

0 Answers0