在一个循环之后,程序在新组件行处抛出异常并退出。如何循环直到用户选择有效的文件?
while(!next){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), folderChooser());
try{
EmbeddedMediaPlayerComponent a = new EmbeddedMediaPlayerComponent();
a.release();
next = true;
}
catch(Exception e){
next = false;
}
}
错误:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class uk.co.caprica.vlcj.binding.LibVlc
at uk.co.caprica.vlcj.binding.LibVlcFactory.create(LibVlcFactory.java:158)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:236)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.onGetMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:278)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:168)
at sv1.MainRun.try1(MainRun.java:107)
at sv1.MainRun.<init>(MainRun.java:82)
at sv1.Start.main(Start.java:7)
答案 0 :(得分:1)
NoClassDefFoundError ncdx2 = null;
try {
...
} catch(NoClassDefFoundError ncdx) {
ncdx2 = ncdx;
}
if(ncdx != null) {
System.out.println("Try again: " + ncdx.getMessage());
} else {
next = true;
}
这样可行,但绝对不建议使用没有错误作为循环的终止条件。是否有任何方式来检查这个 崩溃?希望您使用的API有一些关于某些isOkeyDokey()
函数的信息。如果没有,你可能会做一些反思。任何事都比使用错误替代逻辑更好。
更多信息:https://www.google.com/search?q=how+to+catch+an+error+in+java
答案 1 :(得分:0)
见以下修改
try
{
while(!next)
{
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), folderChooser());
EmbeddedMediaPlayerComponent a = new EmbeddedMediaPlayerComponent();
a.release();
next = true;
}
}
catch(Exception e){
next = false;
}
答案 2 :(得分:-1)
好吧,我会尝试移动试用线
while(!next){
try{
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), folderChooser());
EmbeddedMediaPlayerComponent a = new EmbeddedMediaPlayerComponent();
a.release();
}
catch(Exception e){
}
}