1

I have a class called TestInventory.java, with other classes in the default package, all in the src folder. However, when I run it, I get:

Error: Could not find or load main class

Here is my code

 import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Scanner;
    //@ author Jane Choe
    public class TestInventory {

        public void main(String[] args) throws FileNotFoundException {
            Inventory inv = new Inventory();

            // TODO:  Read in the input file and populate the movieList. Manage exceptions.
            // On a failed movie load print the message
            // "Exception " + e.getMessage() + " for film " + title. No loading."
            FileReader file = new FileReader("movies_db.txt");
            Scanner sc = new Scanner (file);

            while (sc.hasNextLine()){
                String line = sc.nextLine();
                String [] splitline = line.split("-");
                //if (splitline[6]== null){// has as many parameters as an action movie
                    //try {// try adding to action
                System.out.println("p");
                        inv.add(new Action(splitline[0], Integer.parseInt(splitline[1]), Integer.parseInt(splitline[2]), 
                                Integer.parseInt(splitline[3]), Integer.parseInt(splitline[5])));

                    //}
                    //catch{
                    //  System.out.println("Exception + e.getMessage() + " for film " + title. No loading.");
                    //}
                //} // if loop
            }/*
            else{
                try {// try adding to RomCom
                    inv.add(RomCom((splitline[0], Integer.parseInt(splitline[1]), Integer.parseInt(splitline[2]), 
                            Integer.parseInt(splitline[3]), (splitline[4]),
                            Integer.parseInt(splitline[5]), Integer.parseInt(splitline[6]));
                }
                catch{
                    System.out.println("Exception + e.getMessage() + " for film " + title. No loading.");
                }
            }
        }
        */


        //DO NOT CHANGE
        System.out.println("Inventory should now contain file contents.");
                            System.out.println(inv.toString());

                            Movie starWars = new Action("Star Wars - A New Hope", 1977, 121, 3.8, 89);
                            inv.add(starWars);

                            Movie numberFour = new Action("I Am Number Four", 2011, 101, 3.2, 11);
                            inv.add(numberFour);

                            Movie someoneLikeYou = new RomCom("Someone Like You", 2011, 101, 3.2, 2, 5);
                            inv.add(someoneLikeYou);

                            Movie crazyStupidLove = new RomCom("Crazy, Stupid, Love 2", 2013, 113, 3.9, 1, 3);
                            inv.add(crazyStupidLove);

                            System.out.println("Inventory should now contain 13 movies. " + (inv.size() == 13));
    /* add this in later
                            if(inv.remove(crazyStupidLove.getTitle(), crazyStupidLove.getYear())) {
                                System.out.println("Successfully removed 'Crazy, Stupid, Love'");
                                if(!inv.remove(crazyStupidLove.getTitle(), crazyStupidLove.getYear())) {
                                    System.out.println("Successfully ignored second remove attempt for 'Crazy, Stupid, Love'");
                                }
                            }
    */
                            try {
                                inv.add(new RomCom("27 Dresses", 2008, 103, 4.4, 1, 1));
                            } catch (IllegalArgumentException e) {
                                System.out.println("Successfully threw exception on invalid parameter.");
                            }

                            try {
                                inv.add(someoneLikeYou);
                            } catch (MovieInventoryException e) {
                                System.out.println("Successfully threw exception on duplicate add attempt.");
                            }

                            System.out.println("Inventory should now contain 12 movies. " + (inv.size() == 12));

                            System.out.println("Inventory should not contain 'The Matrix'? " + !inv.contains("The Matrix", 1999));
                            System.out.println("Inventory should not contain 'Something Borrowed'? " + !inv.contains("Something Borrowed", 2009));
                            System.out.println("Inventory should not contain '27 Dressed'? " + !inv.contains("27 Dressed", 2008));

                            System.out.println("\n" + inv.toString());
    }

    }

I also have a red exclamation point next to my project.

Any help would be greatly appreciated.

2
  • I forgot to say that I am using Eclipse Commented Dec 5, 2015 at 2:16
  • Take a look at the answer to a similar problem here: stackoverflow.com/a/17355989/2295256 Commented Dec 5, 2015 at 2:21

1 Answer 1

3

You are forgetting the "static" in your main method.

public static void main(String[] args) {
  //do something
}
Sign up to request clarification or add additional context in comments.

2 Comments

If this answer helped you, consider marking it as accepted by clicking the green check mark :)
@trying haha no worries dude, we all undermine the simple things in life sometimes. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.