错误:无法找到或加载主类?

时间:2015-12-05 02:10:24

标签: java

我有一个名为TestInventory.java的类,默认包中有其他类,都在src文件夹中。但是,当我运行它时,我得到:

错误:无法找到或加载主类

这是我的代码

 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());
    }

    }

我的项目旁边还有一个红色感叹号。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

你忘记了"静态"在你的主要方法中。

if( ctype_digit( (string)$i ) )
{
    return TRUE;
}