gpt4 book ai didi

java - 已编译.Jar Crashes(无Java控制台),但在Eclipse中编译并运行?

转载 作者:行者123 更新时间:2023-12-03 02:20:26 42 4
gpt4 key购买 nike

我正在使用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中可以正常工作的东西和DOES)

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();
}

最佳答案

右键单击您的Desktop Project-> Build Path-> Configure,然后检查“Sources”中是否为android Assets文件夹,并在“Order and export”中进行检查。
另外,在导出可运行jar时,请选中“将所需的库打包到生成的库中”。

关于java - 已编译.Jar Crashes(无Java控制台),但在Eclipse中编译并运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13711680/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com