Add the source code to the project
Follow these steps to add the source to the project.
- Open the following source code, select all, and copy it to the clipboard: MainApp.java.
- Add the Java source file with Eclipse or NetBeans.
Option 1: Eclipse
-
In the Package Explorer view, select the project and right-click.
-
From the context menu, select New > Class. The New Java Class wizard opens.
-
Type the Name of the class: MainApp.
-
Click Finish.
-
The MainApp.java file is automatically opened in the editor. Replace its contents with the source code you copied in the previous step.
-
A line at the top of the pasted code is underlined in red. Click on that line; a pop-up appears. Select the first option (Move 'MainApp.java' to package '...') to resolve the error.
Option 2: NetBeans
-
In the Projects view, select the project and right-click.
-
From the context menu, select New > Java Class... The New Java Class wizard opens.
-
Modify the Class Name to be MainApp.
-
Click Finish.
-
The MainApp.java file automatically opens in the editor. Replace its contents with the source code you copied in the previous step.
-
A line at the top of the pasted code is underlined in red. Click on the light bulb next to that line; a pop-up appears. Select the first option (Move class to correct folder) to resolve the error.