@Override public void run() {while(true) {while((doc.getLength()==0)||(ao1==false)) {try {this.sleep(500);} catch (InterruptedException ex){} } try {try {if(ao1) {text=this.doc.getText(0,doc.getLength()); reader = new StringReader(text); source = new InputSource(reader); source.setSystemId("StringReader"); } } catch (BadLocationException ex){} if(ao1) xmlReader.parse(source); //*THIS GENERATE java.lang.NullPointerException* }//error here catch (IOException ex) {} catch (SAXException ex){System.out.println("Error: "+ex.toString());} try {this.sleep(2000);}catch (InterruptedException ex) {} } } Thanks