编译.Jar崩溃(没有java控制台),但在Eclipse中编译和运行?

时间:2012-12-04 20:51:03

标签: java eclipse audio libgdx compiled

我正在使用Libgdx对游戏进行编码,并且它使用Gdx.files.internal(“file”)等方法来加载文件,这应该在导出应用程序时起作用,因为这是它的意图

有些文件被复制到USER目录并从那里加载(音频)这是导致应用程序崩溃的原因吗?如上所述:Java application runs properly in Eclipse, but not as .jar

如果有人能给我一个关于发生什么事情的想法,那就太好了,它也没有为我启动java控制台,所以我不知道

编译后的.jar在这里:https://www.dropbox.com/s/rz9v7lkdsj78z20/RUSHmup.jar(里面也有库)

继承了我认为导致问题的音频加载代码(但我能看到的只是那些能够正常工作并且在Eclipse中运行的东西)

if(!Gdx.files.external("test.wav").exists()){
            String f = copySong(FILE);
        }
        if(Gdx.files.external("test.wav").exists()) {
        //  String ss = copySong(FILE);
            String songPath = Gdx.files.getExternalStoragePath() + Gdx.files.external("test.wav").path();
            //System.out.println("B4: " + songPath);
            songPath.replace('\\', '/');
            //System.out.println("AF: " + songPath);
            song = minim.loadFile(songPath,2048);//"C:/users/seantest/test.wav", 2048);

        }

        String external = Gdx.files.getExternalStoragePath();
        external.replace('\\', '/');

        Gdx.files.internal("data/audio/1.wav").copyTo(Gdx.files.external("1.wav"));
        Gdx.files.internal("data/audio/2.wav").copyTo(Gdx.files.external("2.wav"));
        Gdx.files.internal("data/audio/3.wav").copyTo(Gdx.files.external("3.wav"));
        Gdx.files.internal("data/audio/go.wav").copyTo(Gdx.files.external("go.wav"));
        count3 = minim.loadSample(external + "3.wav");
        count2 = minim.loadSample(external + "2.wav");
        count1 = minim.loadSample(external + "1.wav");
        countGo = minim.loadSample(external + "go.wav");

        audioData = new RSAudioData(this);

        if(song!=null){
            System.out.println("Song Info: " );
            System.out.println(song.length() + " " + song.sampleRate() + " " + song.bufferSize());
            beat = new BeatDetect(song.bufferSize(), song.sampleRate());
            beat.setSensitivity(300);  
            bl = new RSMBeatListener(beat, song); 
            fftLog = new FFT(song.bufferSize(), song.sampleRate());
            fftLog.logAverages(22, 3);
            max = new float[fftLog.avgSize()];
              for(int i = 0; i < max.length-1; i++)
                max[i] = 0;
        }
    }

    public String copySong(String file) {
        externalFile = Gdx.files.external("test.wav");
        Gdx.files.internal(file).copyTo(externalFile);
        exFile = Gdx.files.getExternalStoragePath() + "test.wav";
        System.out.println(exFile);
        return exFile;
    }

    public String sketchPath() {
        return Gdx.files.getExternalStoragePath();
    }

1 个答案:

答案 0 :(得分:0)

右键单击桌面项目 - &gt;构建路径 - &gt;配置并检查“Sources”中是否为android资源文件夹,并在“Order and export”中进行检查。 另外,在导出可运行的jar时,请选中“将所需的库打包到生成的库中”。