作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个线程必须验证字符串是否等于错误之一。如果是,他设置一个flag=1。我的问题是线程永远不会进入 if 并且他给出了这个异常:java.util.NoSuchElementExcpetion:没有找到行
。这是我的代码的一部分:
String can = String.valueOf(jComboBox1.getSelectedItem());
String pad = String.valueOf(jComboBox2.getSelectedItem());
final String err = String.valueOf("WARNING: NO PAD nodes found on channel "+can+" . Exit!");
final CountDownLatch latch = new CountDownLatch(1);
final int[] flag = new int[1];
flag[0]=0;
try {
if(pathFile!=null){
p = Runtime.getRuntime().exec("testpad -i -c"+can+" -n"+pad+" "+pathFile);
final InputStream inStream = p.getInputStream();
Thread uiThread = new Thread("UIHandler") {
@Override
public void run() {
InputStreamReader reader = new InputStreamReader(inStream);
Scanner scan = new Scanner(reader);
while (scan.hasNextLine()) {
System.out.println(scan.nextLine());
if(err==scan.nextLine()){
flag[0] = 1;
}
latch.countDown();
}
}
};
uiThread.start();
latch.await();
if(flag[0]!=1){
this.dispose();
new menu().setVisible(true);
}
else{
Exception e = new Exception("Error!");
Component f = null;
JOptionPane.showMessageDialog(f, err, e.getMessage(), JOptionPane.WARNING_MESSAGE);
}
}
else{
Exception e = new Exception("Error!");
Component f = null;
JOptionPane.showMessageDialog(f, "Choose a configuration file", e.getMessage(), JOptionPane.WARNING_MESSAGE);
}
} catch (IOException ex) {
Logger.getLogger(inizio.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(inizio.class.getName()).log(Level.SEVERE, null, ex);
}
我是java新手,我已经尝试了我所知道的一切。
最佳答案
当你这样做时:
System.out.println(scan.nextLine());
if(err==scan.nextLine()){
您的代码读取两行而不是一行。
String s = scan.nextLine()
System.out.println(s);
if(err.equals(s){
应该工作得更好。
关于java - 线程 java.util.NoSuchElementExcpetion 中的异常 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30759546/
我正在尝试了解网络应用程序(L10N)自动化本地化测试的可能性。首先,我们决定看看是否可以在不打开应用程序的情况下在文件中收集 HTML 纯文本(母语)并将其与我们拥有的术语表进行比较。我可以使用 j
我有一个线程必须验证字符串是否等于错误之一。如果是,他设置一个flag=1。我的问题是线程永远不会进入 if 并且他给出了这个异常:java.util.NoSuchElementExcpetion:没
我是一名优秀的程序员,十分优秀!