java - 将数组传递给方法,遇到错误为 "cannot find symbol songArray"

标签 java

我正在尝试将数组传递给方法。我在编译时不断收到错误,错误是“找不到符号songArray”。

SongTestDrive

import javax.swing.JOptionPane;
public class SongTestDrive {
    public static void main(String[] args) {

        String[] Song = { "Song title: soul to squeeze", "Artist: Red Hot Chili Peppers", "Genre: Funk Rock", "Year: 1993", "Song title: Slaughtered",
                "Artist: PanterA", "Genre: Groove Metal", "Year: 1994" };

        songArray(); //<--- Im having issues right here//
    }
}

歌曲

import javax.swing.JOptionPane;

public class Song {
    String name;
    String artist;
    String genre;
    int year;

    public void songArray(String[] Song) {
        for (String o : Song) {
            JOptionPane.showMessageDialog(null, o);
        }
    }
}

任何帮助都会有用。

最佳答案

您需要一个实例对象来调用其他类方法。

这样做

new Song().songArray(Song); 

Song s = new Song()
s.songArray(Song); 

最好的做法是尝试维护 java 命名约定。

例如

Change String[] songs ={}; to String[] Song ={}; and make call like below

new Song().songArray(songs); 

关于java - 将数组传递给方法,遇到错误为 "cannot find symbol songArray",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20674782/

相关文章:

java - 我是否需要重写类 <A> 的 equals 方法才能获取 Set<A> 中的唯一对象?

java - 如何在java中拆分数字?

java - 警报对话框 : a string is not converting to bold text

java - 以编程方式启动 apache derby

java - Web 服务无法正常工作

java - 读取隐藏的 zip 文件

java - 如何删除数组中的最小值?

java - 如何使用相对路径加载 .dll - Java

java - 如何动态添加一行到 GXT 网格

java - RecyclerView onCreateViewHolder位置背景颜色