 <p>Your <code>codeResult()</code> method throws <code>Exception</code></p> <pre><code>public int coderesult (String urlstring) throws Exception { </code></pre> <p>Therefore, you must either catch it specifically <code>catch(Exception ex)</code> , or declare that your throw it from your method.</p> <p>When catching exceptions, you either catch a specific exception type, or a more generic parent exception type. You could combine all catches into one catch, because all built in java exceptions extend from Exception</p> <pre><code>catch(Exception ex){ ex.printStackTrace(); } </code></pre>