using Bufferdwriter why am I receiving main class not found or can't load?

118 Views Asked by At

I create a program that accepts user input. Based on the sales amount I am requesting the data go to either a low sales txt file or a high sales txt file. When I run the program I receive error Error: Could not find or load main class HighandLowSales. How can it not find or load the main class?

My previous post regarding the if else statement in case you would like to see: How to specify which file to write to?

import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;

public class HighandLowSales
{

    public static void main(String[] args) 
    {

       Scanner input1 = new Scanner(System.in);
       Path highPerformer =
               Paths.get("C:\\Users\\C\\Desktop\\IS103 "
                       + "Programming Logic\\Week7\\HighSales.txt");
       Path lowPerformer = 
               Paths.get("C:\\Users\\C\\Desktop\\IS103 Programming Logic\\"
                       + "Week7\\LowSales.txt");


               String delimiter = ",";
               String s;
               int id;
               String firstName;
               String lastName;

               double currentSales;
               final int QUIT = 999;
               try
               {
                  Scanner input = new Scanner(System.in);
                   OutputStream output = new
                     BufferedOutputStream(Files.newOutputStream(highPerformer, CREATE));
                  OutputStream output1 = new
                     BufferedOutputStream(Files.newOutputStream(lowPerformer, CREATE));

                  BufferedWriter writer = new
                     BufferedWriter(new OutputStreamWriter(output));
                  BufferedWriter writer1 = new
                     BufferedWriter(new OutputStreamWriter(output1));

                  System.out.print("Enter employee ID number >> ");
                  id = input.nextInt();
                  while(id != QUIT)
                  {
                     System.out.print("Enter first name for employee #" + 
                             id + " >> ");
                     input.nextLine();
                     firstName = input.nextLine();
                     System.out.print("Enter last name for employee # " +
                             id + " >> ");
                     input.nextLine();
                     lastName = input.nextLine();
                     System.out.print("Enter current month sales in whole dollar "
                             + "for employee #" + id + " >> ");
                     input.nextLine();
                     currentSales = input.nextDouble();
                     s = id + delimiter + firstName + delimiter + lastName + delimiter
                             + currentSales;


                 if (currentSales>1000)
                 {
                     writer.write(s);
                 }   
                 else
                 {
                     writer1.write(s);
                 }



                   writer.newLine();
                   writer1.newLine();
                   System.out.print("Enter next ID number or " + QUIT 
                           + "to quit");
                   id = input.nextInt();


                  }
                 writer.close();
                 writer1.close();

               }
        catch(Exception e)
        {
           System.out.println("Message: " + e);
        }          

    }          
}
1

There are 1 best solutions below

0
On BEST ANSWER

The file HighandLowSales.java must be exactly in the same case, not for instance HighAndLowSales.java. Either that or you are not executing the application with the correct class path: java -cp . HighandLowSales. But as it seems you just clicked the jar, I guess it is the case-sensitive nature of java file names (in jars, under Linux, MacOSX).

(Also it is really customary to no longer use the default (=no) package.)