I have a simple WebViewClient class that should return all the <p>
elements of the page I am currently on (in a webview)
Here is the code
public class SearchClient extends WebViewClient {
class MyJavaScriptInterface {
@SuppressWarnings("unused")
public void processHTML(String[] html) {
Log.w("Length", String.valueOf(html.length));
for(String s : html)
{
Log.w("Row", s.toString());
}
}
}
public SearchClient(WebView wv)
{
wv.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
}
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.HTMLOUT.processHTML(document.getElementsByTagName('p'));");
}
}
document.getElementsByTagName
clearly is returning the elements because "Log.w" line in the processHTML function has over 100 strings ... but the for loop crashes. Why is this??