Java 当方法不是';不是静态的吗?

Java 当方法不是';不是静态的吗?,java,arraylist,static,Java,Arraylist,Static,我试图为一个理论视频商店制作一个面向对象的库存系统 我不断收到以下错误消息: non-static variables xyz cannot be accessed from a static context. 我在静态上下文中找到的所有信息都是关于一个方法是静态的,另一个不是静态的,但是我的方法都不是静态的 在这段代码中,我两次收到错误消息,我不明白为什么 if (enterOption == 1) { Movie movieNew = new Movie (titleInput,

我试图为一个理论视频商店制作一个面向对象的库存系统

我不断收到以下错误消息:

non-static variables xyz cannot be accessed from a static context.
我在静态上下文中找到的所有信息都是关于一个方法是静态的,另一个不是静态的,但是我的方法都不是静态的

在这段代码中,我两次收到错误消息,我不明白为什么

if (enterOption == 1) {
    Movie movieNew = new Movie (titleInput, yearInput, directorInput, ratingInput, genreInput);
    VideoShop.movies.add(movieNew);  
} else {
    UI.runUI();
}
我从
VideoShop.movies.add(movieNew)获得它
UI.runUI()方法调用

完整方法:

public void createMovie ()
{
    Scanner sc = new Scanner (System.in);

    System.out.println ("Title: ");
    String titleInput = sc.next();

    System.out.println ("Year: ");
    int yearInput = sc.nextInt();

    System.out.println ("Director: ");
    String directorInput = sc.next();

    System.out.println ("Rating [G / PG / M / MA15 / R18]: ");
    String ratingInput = sc.next();

    System.out.println ("Genre [a - Action/ b - Drama/ c - Comedy/ d - Musical/ e - Family/ f - Documentary]: ");
    String genreInput = sc.next();

    System.out.println ("Format [VCD/DVD]: ");
    String formatInput = sc.next();

    System.out.println ("Cost: ");
    double costInput = sc.nextDouble(); 

    System.out.println ("Quantity: ");
    int quantityInput = sc.nextInt();


    System.out.println("Confirm?");
    System.out.println("1. Yes 2. No, return to main menu");

    System.out.println("Enter option: ");
    int enterOption = sc.nextInt();

    if (enterOption == 1) {
        Movie movieNew = new Movie (titleInput, yearInput, directorInput, ratingInput, genreInput);
        VideoShop.movies.add(movieNew);

    } else {
        UI.runUI();
    }
}

很可能,
VideoShop.movies
是非静态字段。您应该创建一个对象,而不是使用
VideoShop.movies

VideoShop shop = new VideoShop();
shop.movies.add(movieNew);
UI
相同:

UI ui = new UI();
ui.runUI();

很可能,
VideoShop.movies
是非静态字段。您应该创建一个对象,而不是使用
VideoShop.movies

VideoShop shop = new VideoShop();
shop.movies.add(movieNew);
UI
相同:

UI ui = new UI();
ui.runUI();

有人能解释一下为什么我会有这个问题吗?你在你的main()中使用这个吗?Java的main是静态的…发布您的完整方法。我没有使用main方法。有人能解释一下为什么我会遇到这个问题吗?您在main()中使用这个吗?Java的main是静态的…发布完整的方法。我没有使用main方法