Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以使用Java中数组中调用的方法的参数吗_Java_Arrays_Methods_Parameters - Fatal编程技术网

我可以使用Java中数组中调用的方法的参数吗

我可以使用Java中数组中调用的方法的参数吗,java,arrays,methods,parameters,Java,Arrays,Methods,Parameters,这在main()方法中: Movie[] list = new Movie[6]; list[0] = new Animated(.25, 700.000, "Mulan", "Barry Cook", 1998, 15.000); list[1] = new Animated(.23, 45.000, "TMNT", "Steve Barron", 1990, 12.000); list[2] = new Documentary(12, 7.000, "Nixon", "Oliver Sto

这在
main()
方法中:

Movie[] list = new Movie[6];

list[0] = new Animated(.25, 700.000, "Mulan", "Barry Cook", 1998, 15.000);
list[1] = new Animated(.23, 45.000, "TMNT", "Steve Barron", 1990, 12.000);
list[2] = new Documentary(12, 7.000, "Nixon", "Oliver Stone", 1995, 50.000);
list[3] = new Documentary(10, 4.500, "JFK", "Oliver Stone", 1991, 35.000);
list[4] = new Drama(3.500, 8.25, "Belly", "Hype Williams", 1998, 20.000);
list[5] = new Drama(4.500, 9.00, "42", "Brian Helgeland", 2013, 16.000);

System.out.print(menu());
System.out.print("Select and menu option 1-5: ");
choice = input.nextInt();
do
{
    switch(choice)
    {
        case 1: movieList(list);
        break;
我正在调用
movieList(list)
方法,该方法存在于
main
之外的类中:

public static void movieList(Movie[] a)
{
    System.out.printf("\n\n%-10s %-10s %-10s %-10s %-10s", "TITLE", "YEAR",
    "REVENUE", "PROFIT", "CATEGORY");
    System.out.printf("\n\n%-10s", Movie[0].getTitle());
}
这就是我在
案例1
中调用的方法,我一直试图使用一个参数,但指针指向Movie时出现“找不到符号”错误。
我一直在搜索,我开始认为我无法通过这种方式访问此值。

您的
movieList
方法中
Movie[]
参数的名称是
a
,因此尝试使用
a[0].getTitle()
而不是
Movie[0].getTitle()
。方法中的参数总是通过名称而不是类型来访问。

方法中
Movie[]
参数的名称是
a
,因此尝试使用
a[0].getTitle()
而不是
Movie[0].getTitle()
。方法中的参数总是通过名称而不是类型进行访问