netbeans

How To Solve Error “No Main Class Found in NetBeans”

How To Solve Error “No Main Class Found in NetBeans”
Have you ever been working with NetBeans and got a very frustrating error that says: “No Main Class Found”?  We are going to show you to how to solve that problem in this article.  But first we must start with some background so you can understand the process.

Let's start with knowing what NetBeans actually is. So NetBeans is an integrated development environment (IDE) originally used for Java but in addition to Java development, it also has extensions for other languages like PHP, C++, C, HTML5, and JavaScript. It can be run on different operating systems like Windows, macOS, Linux, and Solaris. NetBeans based applications which include the NetBeans IDE and others can also be extended by third-party developers. In July 2006, under Sun's Common Development and Distribution License (CDDL) the NetBeans IDE got licensed.  Recently NetBeans IDE and Platform were donated to the Apache Foundation by Oracle. In April 2019, it underwent a business development cycle and passed out as a top-level project so right now NetBeans is licensed under the Apache License 2.0.

NetBeans integrated development environment is an open source platform. NetBeans IDE supports the development of all Java application types which include Java SE, JavaFX Java ME, web, EJB, and mobile applications out of the box. The other features of IDE include Maven support, refactorings, an Ant-based project system, version control (which supports Git, CVS, Mercurial, Subversion and Clearcase).

NetBeans provide the facility to build software applications from a set of modular components also known as modules. These modules provide all the basic functions of the IDE. each of them have a well-defined function such as supporting different languages, editing or support for the CVS versioning system and SVN, it got all the components to support development of Java in a single download, allowing the user to start working immediately, but for other languages and new features NetBeans needs to be extended, new modules and packages need to be installed. For instance, Sun Java Studio Creator from Sun Microsystem, Sun Java Studio Enterprise, and Sun Studio are all based on the NetBeans IDE.

Main Method

Moving on to the main method, in Java language, a Java application can't be built without a main method. A Java application is defined as a public Java class with a main() method.

public: It is an access specifier. The public keyword is used before the main so that the Java virtual machine can identify the program's point of execution. If the access specifier is other than public, that is private or protected, it will not be visible to JVM and the program wouldn't know its execution point.

static: any function becomes static can be made static by using the keyword static. Static methods are the functions that can be run or invoked without the creation of any objects, so to call the main function, objects are not needed. It is necessary to call the main method without creating an object hence static is used

void: this specifies the run-type which is null. The compiler acknowledges that the method isn't returning any kind of value.

main(): It is a default syntax that is already defined in the Java Virtual Machine. JVM calls this function to compile a program line by line and end the compilation after the function is completed. The main method can also be overloaded

String args[]: The main() method also accepts some kind of data input from the user. It accepts an array of strings through cmd line arguments. Command-line arguments are passed through the args parameter, which is an array of Strings.

Resolving the Error

Now we know that the main method is quite important to run a program on a JVM. Following are the possible solutions to overcome the error “Main class not found in NetBeans”:

The standard way of running the project with main:

If you just want to run the file, right-click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)

Correct syntax signature of main:

Specifying the main class:

Memory/Cache SPACE ERROR:

If you have tried this and still it is not working then:

Go to Home/NetBeans/nb/var/cache and delete the Cache folder. Then open the NetBeans IDE again and run the project

If things still don't work, then try the following steps:

  1. Select the project from the project explorer
  2. Select Run from the Menu Bar

Select Compile

Instalați cel mai recent joc de strategie OpenRA pe Ubuntu Linux
OpenRA este un motor de jocuri de strategie în timp real Libre / Free care recreează primele jocuri Westwood, cum ar fi clasicul Command & Conquer: Re...
Instalați cel mai recent Dolphin Emulator pentru Gamecube și Wii pe Linux
Emulatorul Dolphin vă permite să jucați jocurile alese de Gamecube și Wii pe computerele personale Linux (PC). Fiind un emulator de joc liber disponi...
Cum se folosește GameConqueror Cheat Engine în Linux
Articolul acoperă un ghid despre utilizarea sistemului de înșelăciune GameConqueror în Linux. Mulți utilizatori care joacă jocuri pe Windows folosesc ...