实例化类时“无法解析为类型”错误

问题描述

我创建了一个名为“soundStuff.java”的类

import java.io.File;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class soundStuff {
    void playSounds(String Location) {
        try {
            File soundpath = new File(Location);
            
            if(soundpath.exists()) {
                AudioInputStream audioInput = AudioSystem.getAudioInputStream(soundpath);
                Clip clip = AudioSystem.getClip();
                clip.start();
            }
            
            else {
                System.out.println("Can't find file");
            }
        }
        catch(Exception ex) {
            ex.printstacktrace();
        }
    }
}

每当我尝试在我的 Game.java 函数中实例化它

public static void playRandomSound() {
        Random random = new Random(System.currentTimeMillis()); //seeding random with current time
        int soundRnd = random.nextInt(3);
        switch(soundRnd) 
        {
        case 1:
            String filepath = "Death1.wav";
            soundStuff soundobject = new soundStuff();
            soundobject.playMusic(filepath);
            
        case 2:
            String filepath = "Death2.wav";
            soundStuff soundobject = new soundStuff();
            soundobject.playMusic(filepath);
            
        case 3:
            String filepath = "Death3.wav";
            soundStuff soundobject = new soundStuff();
            soundobject.playMusic(filepath); 
            
        }
    }

我收到“soundStuff 无法解析为类型”错误,尽管在过去 30 多分钟的大部分时间里,我都在互联网上特别是这个网站上进行了搜索,但我无法解决。非常感谢任何和所有帮助 TIA

解决方法

您需要编译(错误命名 - 类名在 Java 中以大写开头)soundStuff 和您的 Game。目前还没有看到。

,

从表面上看,问题是一些 java 技巧。删除项目并从头开始重新制作它解决了问题。感谢大家的帮助。