Results 1 to 15 of 15

Thread: Package help

  1. #1
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Package help

    Hi everyone, I'm new to this site and I need a bit of help with my java coding. I'm using NetBeans to write my Program and I seem to be getting a few errors that I don't understand. I'm only getting 5 or so errors but its the same problem throughout the whole code. I believe it has something to do with the package but I'm not so sure. I've highlighted the parts of code in red which are showing an error, they are all the same problem though. I believe if this one problem is corrected then all of the problems should resolve themselves. Help is much appreciated.

    -----------------------------------------------------------

    Java Code:
    package policymanager;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Scanner;
    import java.util.Calendar;
    import java.text.SimpleDateFormat;
    import java.util.*;
    
    /**
    *
    * 
    */
    public class PolicyManager {
    
        final private static Scanner UserInput = new Scanner(System.in);
    
        private static String clientName;
        private static String number;
        private static String payment;
        private static String reference;
        private static String terms[] = {"Annual", "Monthly"};
        private static String numbers[] = {"One", "Two", "Three", "Four", "Five"};
    
        private static int b;
        private static int excessAmount;
        private static int gadgetLimit = 0;
        private static int rejectedItems = 0;
    
        private static double value;
        private static double mostExpensive;
        private static double premium = 0;
        private static double total = 0;
        private static double finalPremium = 0;
        private static double endPremium = 0;
        private static double finalTotal = 0;
        private static double premium1[][] = {{4.99, 6.15, 7.30}, {9.99, 12.35, 14.55}, {14.99, 18.60, 21.82}};
      
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws FileNotFoundException, IOException {
            
    
            //Display Menu
            int choice = returnMenu();
    
            //Menu loop
            while (choice != 0) {
                if (choice == 1) {
    
                    [COLOR="#FF0000"]Policy[/COLOR] newPolicy = new Policy();
                    new [COLOR="#FF0000"]Policy[/COLOR] = createNewPolicy(newPolicy);
    
                } else if (choice == 2) {
    
                    displaySummary();
    
                } else if (choice == 3) {
    
                    displayMonth();
    
                } else if (choice == 4) {
    
                } else {
                    System.out.println("Menu choices 1-4 are valid");
                    System.out.print("\nPlease select a meny item: ");
                    choice = UserInput.nextInt();
    
                }
    
                choice = returnMenu();
            }
        }
    
        public static int returnMenu() {
    
            System.out.println("1. Enter New Policy");
            System.out.println("2. Display Summary of Policies");
            System.out.println("3. Display Summary of Policies for Current Month");
            System.out.println("4. Find and Display Policy");
            System.out.println("0. Exit");
    
            System.out.print("\nPlease select a choice by entering a number and pressing enter:  ");
            int option = UserInput.nextInt();
            UserInput.nextLine();
            return option;
    
        }
    
        public static [COLOR="#FF0000"]Policy[/COLOR] createNewPolicy([COLOR="#FF0000"]Policy[/COLOR] newPol) throws IOException {
    
            System.out.println("----------------------------------------------------");
    
            System.out.println("Today's date: " + getDate() + " has been added to the Policy");
            newPol.setPolicyDate(getDate());
    
            System.out.println("----------------------------------------------------");
    
            Scanner keyboardString = new Scanner(System.in);
            Scanner keyboardInt = new Scanner(System.in);
            boolean validate = false;
            while (validate == false)//A NAME, ONLY NEEDS TO BE 20 CHARS OR LESS. SIMPLE VALIDATION
            {
                System.out.println("Client Name Needed?: ");
                clientName = keyboardString.nextLine();
                if (clientName.length() > 20) {
                    System.out.println("Name must be a maximum of 20 characters");
                    System.out.println("You used " + clientName.length() + " characters");
                } else {
                    newPol.setClientName(clientName);
                    validate = true;
                }
            }
    
            System.out.println("----------------------------------------------------");
    
            validate = false;
            while (validate == false) {
                System.out.println("Please enter reference number?: ");
                reference = keyboardString.next().toUpperCase();
                validate = validateReference(reference);
                if (validate == true) {
                    newPol.setReference(reference);
                }
            }
    
            System.out.println("----------------------------------------------------");
    
            validate = false;
            while (validate == false) {
                System.out.println("Please enter number of items between 1 and 5: ");
                number = keyboardString.next();
                String items = number;
                while (!Character.isDigit(number.charAt(0))) {
                    System.out.println("Your selection needs to be a number.");
                    number = keyboardString.next();
                }
    
                System.out.println("----------------------------------------------------");
    
                validate = false;
                while (!validate) {
                    System.out.print("Highest gadget value? £ ");
                    try {
                        value = keyboardInt.nextDouble();
                        if (value <= 0) {
                            System.out.println("Value must be a positive number");
                        }
    
                        if (value > 0) {
                            value = value * 100;
                            newPol.setHighestGadgetValue((int) value);
                            validate = true;
                        }
                    } catch (Exception e) //Exception handling for non-numbers
                    {
                        System.out.println("Must be in pounds and pence e.g. xx.xx");
                        keyboardInt.next();
                    }
    
                }
    
                System.out.println("----------------------------------------------------");
    
                validate = false;
                while (!validate) {
                    System.out.print("Please enter excess? £ ");
                    try {
                        excessAmount = keyboardInt.nextInt();
                        if (excessAmount == 30 || excessAmount == 40 || excessAmount == 50 || excessAmount == 60 || excessAmount == 70) {
                            newPol.setExcess(excessAmount);
                            validate = true;
                        } else {
                            System.out.println("must be (minimum £30, max £70 in multiples of £10)");
                        }
                    } catch (Exception e) {
                        System.out.println("You entered an invalid input. Please try again");
                        keyboardInt.next();
                    }
                }
    
                System.out.println("----------------------------------------------------");
    
                do {
                    System.out.println("Your payment method?:  a = annual or m = monthly");
                    payment = keyboardString.next();
                    if ((payment.length() == 1) && ((payment.equals("m")) || (payment.equals("a")))) {
                        break;
                    } else {
                        System.out.println("Incorrect input, please enter a valid input.");
                    }
                } while ((payment.length() != 1) || (!payment.equals("m") || (!payment.equals("a"))));
    
                System.out.println("----------------------------------------------------");
    
                if (number.charAt(0) == '1' && mostExpensive > 0 && mostExpensive <= 500) {
                    premium = premium1[0][0];
                    gadgetLimit = 500;
                }
                if (number.charAt(0) == '1' && mostExpensive > 500 && mostExpensive <= 750) {
                    premium = premium1[0][1];
                    gadgetLimit = 750;
                } else if (number.charAt(0) == '1'
                        && mostExpensive > 750 && mostExpensive <= 1000) {
                    premium = premium1[0][2];
                    gadgetLimit = 1000;
                }
    
                if (number.charAt(0) == '2' || number.charAt(0) == '3'
                        && mostExpensive > 0 && mostExpensive <= 500) {
                    premium = premium1[1][0];
                    gadgetLimit = 500;
                }
                if (number.charAt(0) == '2' || number.charAt(0) == '3'
                        && mostExpensive > 500 && mostExpensive <= 750) {
                    premium = premium1[1][1];
                    gadgetLimit = 750;
                } else if (number.charAt(0) == '2' || number.charAt(0) == '3'
                        && mostExpensive > 750 && mostExpensive <= 1000) {
                    premium = premium1[1][2];
                    gadgetLimit = 1000;
                }
    
                if (number.charAt(0) == '4' || number.charAt(0) == '5'
                        && mostExpensive > 0 && mostExpensive <= 500) {
                    premium = premium1[2][0];
                    gadgetLimit = 500;
                }
                if (number.charAt(0) == '4' || number.charAt(0) == '5'
                        && mostExpensive > 500 && mostExpensive <= 750) {
                    premium = premium1[2][1] + 0;
                    gadgetLimit = 750;
                } else if (number.charAt(0) == '4' || number.charAt(0) == '5' && mostExpensive > 750 && mostExpensive <= 1000) {
                    premium = premium1[2][2];
                    gadgetLimit = 1000;
                }
    
                if (excessAmount == 30) {
                    total = premium;
                    finalPremium = total;
                }
    
                if (excessAmount == 40) {
                    total = premium * .05;
                    finalPremium = premium - total;
                }
                if (excessAmount == 50) {
                    total = premium * .1;
                    finalPremium = premium - total;
                }
                if (excessAmount == 60) {
                    total = premium * .15;
                    finalPremium = premium - total;
                } else if (excessAmount == 70) {
                    total = premium * .2;
                    finalPremium = premium - total;
                }
    
                if (payment.charAt(0) == 'a') {
                    endPremium = finalPremium * .1;
                    finalTotal = (finalPremium - endPremium) * 12;
                }
                if (payment.charAt(0) == 'm') {
                    finalTotal = finalPremium;
                }
    
                if (payment.charAt(0) == 'a') {
                    payment = terms[0];
                } else if (payment.charAt(0) == 'm') {
                    payment = terms[1];
                }
    
                if (number.charAt(0) > '5' || number.charAt(0) <= 0
                        || mostExpensive > 1000 || mostExpensive < 0) {
                    payment = "Rejected";
                }
    
                if (number.charAt(0) == '1') {
                    number = items;
                    number = numbers[0];
                }
                if (number.charAt(0) == '2') {
                    number = items;
                    number = numbers[1];
                }
                if (number.charAt(0) == '3') {
                    number = items;
                    number = numbers[2];
                }
                if (number.charAt(0) == '4') {
                    number = items;
                    number = numbers[3];
                } else if (number.charAt(0) == '5') {
                    number = items;
                    number = numbers[4];
                }
                //start of the menu
                //output top lines
            System.out.println("+-----------------------------------+");
            System.out.println("|                                   |");
    
            //Outputs client name line
            System.out.print("|  Client: " + clientName);
    
            //Loops around to make sure that the name is displayed properly
            for (int i = 0; i < 25 - clientName.length(); i++) {
                System.out.print(" ");
            }
            System.out.println("|");
            System.out.println("|                                   |");
    
            System.out.println("|    Date: " + getDate() + " Ref: " + reference
                    + "  |");
    
            //Print terms and items line
            System.out.print("|   Terms: " + payment);
            if (payment.length() == 6) {
                System.out.print("    ");
            } else if (payment.length() == 7) {
                System.out.print("   ");
            } else {
                System.out.print("  ");
            }
            System.out.print("Items: " + number);
            for (int i = 0; i < 8 - number.length(); i++) {
                System.out.print(" ");
            }
            System.out.println("|");
    
            //Prints excess line
            System.out.print("|  Excess: ");
            System.out.print(excessAmount);
            System.out.println("                       |");
            System.out.println("|                                   |");
    
            //Prints terms and Limit per line
            System.out.print("| " + payment);
            if (payment.length() == 6) {
                System.out.print("    ");
            } else if (payment.length() == 7) {
                System.out.print("   ");
            } else {
                System.out.print("  ");
            }
            System.out.println("     Limit per          |");
    
            //Prints Premium and Gadget line
            System.out.print("| Premium: ");
            if (finalTotal == -1) {
                System.out.print("-");
                System.out.print("        ");
            } else {
                System.out.printf("£%2.2f", finalTotal);
                if (finalTotal < 10) {
                    System.out.print("    ");
                } else if (finalTotal < 100) {
                    System.out.print("   ");
                } else if (finalTotal <= 1000) {
                    System.out.print("  ");
                }
            }
            System.out.print("Gadget: " + gadgetLimit);
            if (gadgetLimit < 10) {
                System.out.print("     ");
            } else if (gadgetLimit < 100) {
                System.out.print("    ");
            } else if (gadgetLimit < 1000) {
                System.out.print("  ");
            } else {
                System.out.print("  ");
            }
            System.out.println("  |");
    
            //Prints out bottom two rows
            System.out.println("|                                   |");
            System.out.println("+-----------------------------------+");
      
                //end of the menu
    
                if (number.charAt(0) > 5 && number.charAt(0) <= 0
                        && mostExpensive > 1000 && mostExpensive <= 0) {
                    System.out.println("\nPolicy Rejected");
                    rejectedItems += Integer.parseInt(number);
                }
    
                System.out.println("\nWould you like to re-enter your policy details.");
                System.out.println("Press 1 for Restart and 2 to End: ");
                b = keyboardString.nextInt();
    
                while (b != 1 && b != 2) {
                    System.out.println("\nPress 1 for Restart and 2 to End: ");
    
                }
    
                if (b == 1) {
                    [COLOR="#FF0000"]Policy[/COLOR] newPolicy = new [COLOR="#FF0000"]Policy[/COLOR]();
                    newPolicy = createNewPolicy(newPolicy);
    
                } else {
                    System.out.println("Thank you using Policy Manager, you have selected End.");
    
                }
                File Policy = new File("Policy.txt");
    
                try {
                    PrintWriter pw = new PrintWriter(new FileOutputStream(Policy, true));
                    pw.println(getDate() + "\t" + reference + "\t" + number + "\t"
                            + value + "\t" + excessAmount + "\t" + finalTotal + " " + payment.charAt(0) + "\t"
                            + clientName);        // write data to file specified by output
    
                    // tidy up and close the file
                    pw.close();
                } catch (FileNotFoundException e) {
    
                    // file already exists, prevent overwriting
                    {
    
                    }
    
                }
                System.exit(0);
            }
            return newPol;
        }
    
        public static boolean validateReference(String reference)// SEPARATE METHOD FOR VALIDATING REFERENCE NUMBER DUE TO COMPLEXITY
        {
            boolean validated = false;
    
            if (reference.length() == 6) // is it 6 digits long?
            {
                if (reference.charAt(0) >= 'A' && reference.charAt(0) <= 'Z') // is character a letter between A and Z?
                {
                    if (reference.charAt(1) >= 'A' && reference.charAt(1) <= 'Z') {
                        if (reference.charAt(2) >= '0' && reference.charAt(2) <= '9') // is it a number?
                        {
                            if (reference.charAt(3) >= '0' && reference.charAt(3) <= '9') {
                                if (reference.charAt(4) >= '0' && reference.charAt(4) <= '9') {
                                    if (reference.charAt(5) >= 'A' && reference.charAt(5) <= 'Z') {
                                        validated = true;
    
                                    }
                                }
                            }
                        }
                    }
                }
            }
    
            if (validated == false) {
                System.out.println("Reference number not recognised format - try again");
    
            }
    
            return validated;
    
        }
    
        public static String getDate() {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
            return sdf.format(cal.getTime());
        }
    
        public static String[] readFile(File Read) throws FileNotFoundException {
            int count = 0;
            Scanner countFile = new Scanner(Read);
            while (countFile.hasNext()) {
    
                countFile.nextLine();
                count++;
            }
            String[] lines = new String[count];
            Scanner readFile = new Scanner(Read);
            for (int i = 0; i < count; i++) {
                lines[i] = readFile.nextLine();
    
            }
            return lines;
        }
    
        public static [COLOR="#FF0000"]Policy[/COLOR][] Pol(File Read) throws IOException {
            [COLOR="#FF0000"]Policy[/COLOR][] policies = new [COLOR="#FF0000"]Policy[/COLOR][readFile(Read).length];
            for (int i = 0; i < readFile(Read).length; i++) {
                String line = readFile(Read)[i];
                Scanner lineScanner = new Scanner(line);
                policies[i] = new [COLOR="#FF0000"]Policy[/COLOR]();
                policies[i].setPolicyDate(lineScanner.next());
                policies[i].setReference(lineScanner.next());
                policies[i].setNumberOfGadgets(lineScanner.nextInt());
                policies[i].setHighestGadgetValue(lineScanner.nextInt());
                policies[i].setExcess(lineScanner.nextInt());
                policies[i].setPremium(lineScanner.nextInt());
                policies[i].setPaymentTerms(lineScanner.next());
                policies[i].setClientName(lineScanner.next());
    
            }
            return null;
        }
    
        public static void displaySummary() throws FileNotFoundException { //option 2
          
            File a = new File("Policy.txt");
    
            int totalPolicies = 0;
            int numberOfItems = 0;
            int numberPerPolicy = 0;
            double avgPremium = 0.0;
            int RejectedTotal =0;
            int AverageItems =0;
            int finalTotal = 0;
            String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
            int month1 = 0;
            int month2 = 0;
            int month3 = 0;
            int month4 = 0;
            int month5 = 0;
            int month6 = 0;
            int month7 = 0;
            int month8 = 0;
            int month9 = 0;
            int month10 = 0;
            int month11 = 0;
            int month12 = 0;
    int totalNumberOfLines = 0;
            Scanner keyboardString = new Scanner(a);
           int countMonthlyPolicys = 0;
               int notMonthlyPolicys = 0;
               int totalAvgPremium = 0;
               int annualItems = 0;
               int totalMonthlyItems = 0;
              
               //  Value Holders
               char avgCharHolder;
               int setIntToCharHolder;
             
                int acceptedPolicyCount = 0;
                  
                    int calculateItems = 0;
            while (keyboardString.hasNextLine()){
               
                totalNumberOfLines++;
               String premiumLine = keyboardString.nextLine(); // SETS EVERYTHING TO ONE LINE
               avgCharHolder = premiumLine.charAt(19);
               setIntToCharHolder = Character.getNumericValue(avgCharHolder);
              
              
              
    //          String getDate = keyboardString.next();
    //          String reference = keyboardString.next();
    //          numberOfItems = keyboardString.nextInt();
    //          String mostExpensive = keyboardString.next();
    //          String excess = keyboardString.next();
    //          finalTotal += keyboardString.nextInt();
    //          String terms1 = keyboardString.next();
    //          String name = keyboardString.nextLine();
          
              
               // locate last tab
              
               int findTerms = premiumLine.lastIndexOf("\t");
                    String theTerms = premiumLine.substring(findTerms -1, findTerms);
                   
                    switch(theTerms) {
                        case "A":
                            notMonthlyPolicys++;   
                        case "R":
                            break;
                        case "M":
                        int findPrem = premiumLine.indexOf("\t", 26); // find the first \t in the line
                        String declarePrem = premiumLine.substring(findPrem + 1, findTerms - 2); // locating the premium cost
                        countMonthlyPolicys++;
                       
                        totalAvgPremium = totalAvgPremium + Integer.parseInt(declarePrem);
                         break;
                    }
                avgCharHolder = premiumLine.charAt(19);
         
                    setIntToCharHolder = Character.getNumericValue(avgCharHolder);
             
                     if (avgCharHolder > '0' && avgCharHolder < '6') {
                        //System.out.println(avgCharHolder);
                        setIntToCharHolder = Character.getNumericValue(avgCharHolder);
                        acceptedPolicyCount++;
                        calculateItems = calculateItems + setIntToCharHolder;
                    }
    
           switch(premiumLine.substring(3, 6)) { // LOCATES pos 3 and pos 6 of the String
                  case "Jan":
                    month1++;
                    break;
                case "Feb":
                    month2++;
                    break;
                case "Mar":
                    month3++;
                    break;
                case "Apr":
                    month4++;
                    break;
                case "May":
                    month5++;
                    break;
                case "Jun":
                    month6++;
                    break;
                case "Jul":
                    month7++;
                    break;
                case "Aug":
                    month8++;
                    break;
                case "Sep":
                    month9++;
                    break;
                case "Oct":
                    month10++;
                    break;
                case "Nov":
                    month11++;
                    break;
                case "Dec":
                    month12++;
                    break;
           }
            }
          
         
           
              
       
              
           System.out.println("Monthly: "+ totalMonthlyItems);
            System.out.println("---------------------------------------------");
    
            System.out.println("Total Number of policies:" + totalNumberOfLines);  //998
            System.out.println("Average number of items (Accepted policies):" +  calculateItems / acceptedPolicyCount);
            System.out.printf("Average Monthly Premium: £%.2f ", totalAvgPremium / 100.00);//change this to a double
            System.out.println("");
            System.out.println("Number of Policies per Month (inc. non-accepted): ");
            System.out.println(months[0] + "\t" + months[1] + "\t" + months[2] + "\t" + months[3] + "\t" +
                    months[4] + "\t" + months[5] + "\t" + months[6] + "\t" +
                    months[7] + "\t" + months[8] + "\t" + months[9] + "\t" + months[10] + "\t" + months[11] + "\t");
          
            System.out.println(month1 + "\t" + month2 + "\t" + month3 + "\t" + month4 + "\t" + month5 + "\t" + month6 + "\t" +
                    month7 + "\t" + month8 + "\t" + month9 + "\t" + month10 + "\t" + month11 + "\t" + month12 + "\t");
          
    
            System.out.println("\n---------------------------------------------");
    
            System.out.println("\nWould you like to re-start the program?.");
            System.out.println("Press 1 for Restart and 2 to End: ");
            Scanner KeyboardInput = new Scanner(System.in);
            b = KeyboardInput.nextInt();
    
            while (b != 1 && b != 2) {
                System.out.println("\nPress 1 for Restart and 2 to End: ");
    
            }
    
            if (b == 1) {
    
                returnMenu();
    
            } else {
                System.out.println("\n--------------------------------------------------------");
                System.out.println("Thank you for using Policy Manager, you have selected End.");
                System.out.println("\n--------------------------------------------------------");
    
            }
            System.exit(0);
        }
      
    
        public static void displayMonth() { //option 3
          
            String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
          
            Scanner keyboardString = new Scanner(System.in);
    
            System.out.println("---------------------------------------------");
    
            System.out.println("Please enter the name of the file you wish to search?");
            String filename = keyboardString.next();
          
            while (filename.equals("Policy.txt")) {
                File f = new File(filename);
                if (!f.exists())
                    System.out.println("Error: This file does not Exist");
              
            System.out.println("---------------------------------------------");
              
            System.out.println("Please enter specific month: ");
              
            System.out.println("---------------------------------------------");
              
            System.out.println("Total Number of policies:");
            System.out.println("Average number of items (Accepted policies):");
            System.out.println("Average Monthly Premium:");
            System.out.println("Number of Policies for specific month (inc. non-accepted): ");
          
            System.out.println("---------------------------------------------");
          
            System.out.println("\nWould you like to re-start the program?.");
            System.out.println("Press 1 for Restart and 2 to End: ");
            b = keyboardString.nextInt();
    
            while (b != 1 && b != 2) {
                System.out.println("\nPress 1 for Restart and 2 to End: ");
    
            }
    
            if (b == 1) {
    
                returnMenu();
    
            } else {
                System.out.println("Thank you for using Policy Manager, you have selected End.");
    
            }
            System.exit(0);
        }
    }
    }
    Last edited by CultOfPersonality; 02-25-2014 at 10:52 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    getting 5 or so errors
    Please copy the full text of the error messages and paste them here.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Re: Package help

    Here are the error messages I get. I really have no idea how to correct this
    ---------------------------------------------------------------------

    java.lang.NoClassDefFoundError: Policy
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.ja va:2531)
    at java.lang.Class.privateGetDeclaredMethods(Class.ja va:2531)
    at java.lang.Class.getMethod0(Class.java:2774)
    at java.lang.Class.getMethod(Class.java:1663)
    at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: Policy
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 25)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 58)
    ... 6 more
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 16 seconds)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    java.lang.NoClassDefFoundError: Policy
    The java program can not find a definition for the Policy class. You need to have the Policy.class file properly positioned on the classpath.

    Is there a Policy.class file?
    Where is it located?
    Is the Policy class in a package?
    Does the classpath point to the folder containing the start of the package name?

    What command line was used to execute the program?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Re: Package help

    I don't have a Policy.class file or know what should be in this file. I think this is the main problem which is causing my program not to work properly.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    The source for any class that references the Policy class must have a definition for the Policy to be able to compile without errors. If the compiler can not find a definition for the Policy file, it would not generate a class file that has references to a non-existent file. Somewhere there must be a Policy.class file that the compiler used to generate the class file that was executing and got the error.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    What command line was used to execute the program?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Re: Package help

    I understand that this file is missing but I'm still unsure of how to proceed with this. I now know that a Policy class file must be present but I don't know what should be i nthat Policy class file for the main file to run correctly. I use the program NetBeans to write and execute the program I have.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    Have you looked in all the folders for the Policy.class file?

    Can you try compiling the class that references the Policy class to see if the compiler can find a definition for the Policy class now?
    If the compiler does find it, you need to look and find it.

    I don't know how netbeans can find the class definition for compiling and not for execution.
    Last edited by Norm; 02-26-2014 at 12:14 AM.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Re: Package help

    I've checked the folders and I can't find a Policy class anywhere. Unless this has accidentally been deleted (which is quite possibly whats happened) I'm going to need another Policy class but I honestly have no idea what to put in this Policy class

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: Package help

    You know, I don't get it. Forget about any Policy.class file, you at least have the Policy.java file don't you? You claim that you are writing this program, so this Policy class that is clearly used in -your- code must also have been written by you. It just went missing?

    You didn't write this code at all right?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Default Re: Package help

    Quote Originally Posted by gimbal2 View Post
    You know, I don't get it. Forget about any Policy.class file, you at least have the Policy.java file don't you? You claim that you are writing this program, so this Policy class that is clearly used in -your- code must also have been written by you. It just went missing?

    You didn't write this code at all right?
    I'm fairly new to the java language and to the program NetBeans. I have a decent understanding to the language and with my knowledge of continuing to learn new things with this language, there are still certain things that I do not understand. I was sure there was something missing before I uploaded the code but wasn't quite sure what. Now I know what was missing I can focus on that to build the file that is either missing/accidentally deleted.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    You got an execution time error with a class that was compiled when the compiler could find a definition for the Policy class.

    What happened to that definition?
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Package help

    Interesting... the code pasted above looks similar (but not identical) to the one uploaded to Pastebin on 14 Jan 2014: [Java] java.file - Pastebin.com . The author of the code seems to be one Michael Watts. Just speculating... perhaps you can contact Michael Watts (your prof?) to see if the Policy class source code is available?

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Package help

    I'm fairly new to the java language
    How can a new java programmer write a 700+ line program?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 07-29-2013, 10:21 AM
  2. Replies: 2
    Last Post: 03-26-2013, 07:07 PM
  3. Replies: 3
    Last Post: 03-27-2012, 10:27 AM
  4. run package inside anthor package
    By AhmedAdel in forum AWT / Swing
    Replies: 4
    Last Post: 04-20-2010, 12:52 PM
  5. Replies: 7
    Last Post: 11-09-2009, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •