multithreading - Exception java in thread java.util.NoSuchElementExcpetion -


i have thread must verify if sting equal @ 1 of error. if yes, put flag=1. trouble thread never enter in if , gives exception: java.util.nosuchelementexcpetion: no line found. part of code:

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

i'm new of java , have tried known.

when do:

system.out.println(scan.nextline());  if(err==scan.nextline()){ 

your code reads 2 lines instead of one.

string s = scan.nextline() system.out.println(s);  if(err.equals(s){ 

should work better.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -