I am trying to find out why a program that I created in the NetBeans 7.2.1 IDE will not compile & run in Notepad++. It's just something that is fascinating to me and I would like to know why this is happening.
The program has the main class SalaryDemo and another class Salary that contains the setters and getters for the program. It runs fine with the exception of a calculation error. I got curious to as to how this would run in Notepad++, and after setting up Notepad++, i find that this doesn't run. I tried to shell out to dos and it did the same thing, so I don't think it is Notepad++.
The program uses ArrayList for a sales rep and the sales rep's total annual sales. For some reason the VM cannot find the symbol for the ArrayList or Salary variables. This is to my understanding. I would really appreciate the help with this. It's my first time so go easy on me.
Here's the error message, if you need any other supporting documentation or code, I will get it posted immediately.
NPP_EXEC: "Compile and Run"
CD: Matches Current Directory
Current directory: Matches CD:
javac SalaryDemo.java
Process started >>>
SalaryDemo.java:37: error: cannot find symbol
ArrayList<Salary> salaryArray = new ArrayList<>();
^
symbol: class Salary
location: class SalaryDemo
SalaryDemo.java:37: error: unexpected type
ArrayList<Salary> salaryArray = new ArrayList<>()
^
required: class
found: <E>ArrayList<E>
where E is a type-variable:
E extends Object declared in class ArrayList
SalaryDemo.java:52: error: cannot find symbol
Salary employee = new Salary();
^
symbol: class Salary
location: class SalaryDemo
SalaryDemo.java:52: error: cannot find symbol
Salary employee = new Salary();
^
symbol: class Salary
location: class SalaryDemo
SalaryDemo.java:103: error: cannot find symbol
Salary calcSalary = new Salary();
^
symbol: class Salary
location: class SalaryDemo
SalaryDemo.java:103: error: cannot find symbol
Salary calcSalary = new Salary();
^
symbol: class Salary
location: class SalaryDemo
6 errors
Here is the relevant code
SalaryDemo (main class)
package salarydemofinal;
// Imports the DecimalFormat class and all java.util classes
import java.text.DecimalFormat;
SalaryDemo (main class)
// Public class SalaryDemo matches the filename and is accessable
// by methods outside the SalaryDemo class.
public class SalaryDemo
{
public static void main(String[] args)
{
// Initialize Scanner.
Scanner input = new Scanner(System.in);
// Initialize DecimalFormat to format percentages.
DecimalFormat df = new DecimalFormat("####%"); // Initialize
// Initialize the Array list and use the Salary class to store and
// manipulate elements of the array.
ArrayList<Salary> salaryArray = new ArrayList<Salary>();
String newEmployee = "";
double newSales = 0;
double counter;
double setSalesDifference;
double setTCompDifference;
double nqDifference;
Salary class
package salarydemofinal;
public class Salary {
// Initialize local Salary class variables
private String name; // Holds employee name
private double base = 4000; // Holds fixed monthly salary
private double sales; // Holds annual sales figure data-
private double calc; // Holds data calculate commission
private double com = .25; //Holds commission percentage multiplier
private double totalComp; // Holds sum of commission and annual salary data
private double annualSalary; // Holds data derived from 12 months of base rate
private double salesTarget = 120000;
private double threshold = salesTarget * .80;
private double commission; // sets the commission.
private double annualCompensation;
private double acceleratedSales;
private double notQualified;
This is how I am running the compier in Notepad++ ... I do realize that this is out of the norm however, I feel that this should work. The program isn't that complex.
cd "$(CURRENT_DIRECTORY)" javac $(FILE_NAME) java $(NAME_PART)
In my opinion this is the same method used when you shell out to DOS and try to compile and run the program. At this time, all I really know is that packages contain all of the necessary classes for one program (project). The package statement needs to match in both the main class (SalaryDemo) and the sub-class Salary.
I tried to put this in a C:\\salarydemofinal directory just like the NetBeans IDE and that didn't work. I know I'm probably missing something fundamental. As I mentioned, this should work in my opinion.
I thought about it and took Notepad++ out of the equation and shelled out to DOS to try to compile this as I found another stackoverflow article suggesting that all of the java files need to be compiled at once such as javac *.java. I don't know if it is a positive step or not. The numbers of errors were reduced to 4 but the Scanner wasn't found this time. This was the output:
SalaryDemo.java:31: error: cannot find symbol Scanner input = new Scanner(System.in); ^ symbol: class Scanner location: class SalaryDemo SalaryDemo.java:31: error: cannot find symbol Scanner input = new Scanner(System.in); ^ symbol: class Scanner location: class SalaryDemo SalaryDemo.java:38: error: cannot find symbol ArrayList salaryArray = new ArrayList(); ^ symbol: class ArrayList location: class SalaryDemo SalaryDemo.java:38: error: cannot find symbol ArrayList salaryArray = new ArrayList(); ^ symbol: class ArrayList location: class SalaryDemo 4 errors