0

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

  • Have you imported your `Salary` class ? – hsz Mar 19 '13 at 11:06
  • Pretty hard to tell without seeing the package and import statements for your classes. – Catchwa Mar 19 '13 at 11:07
  • Thank you for the quick reply everyone. I know this is going to sound like I haven't learned anything over the last month but honestly I didn't know I had to import anything other than the java.util and java.text packages, when outside of NetBeans. –  Mar 19 '13 at 13:30

1 Answers1

0

You need to either have the Salary class be in the same package as SalaryDemo or you need SalaryDemo to import it. If they are already in the same package, it means you're not compiling Salary and you'll need to post how you're running the compiler.

It's not actually reporting a problem finding ArrayList, just Salary. When you get this error:

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

what it's telling you is that the parameterized type ArrayList<Salary> doesn't exist. But it doesn't exist because Salary doesn't exist. It's just the result of the earlier error.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
  • Nathaniel that solved it. Previously I posted that the Scanner came up not found and I didn't have the import for that. When I added the import statement it compiled. It was the way I was compiling the program. Here is the article I used. http://stackoverflow.com/questions/7373173/cannot-find-symbol-for-another-class-file Thank you all for your help! –  Mar 19 '13 at 14:32