title: Uncaught ReferenceError: myFunction is not defined at null:1 Android exception in webview
body: <p>I am calling javascript function from an activity but I am getting <code>Uncaught ReferenceError: myFunction is not defined at null:1</code> error. Here is my files </p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.androidexample;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Context;
  import android.view.Menu;
  import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          WebView webview = (WebView)this.findViewById(R.id.webView1);
          WebSettings webSettings = webview.getSettings();
  
          // Enable Javascript for interaction
          webSettings.setJavaScriptEnabled(true);
  
          // Make the zoom controls visible
          webSettings.setBuiltInZoomControls(true);
  
          // Allow for touching selecting/deselecting data series
          webview.requestFocusFromTouch();
  
          // Set the client
          webview.setWebViewClient(new WebViewClient());
          webview.setWebChromeClient(new WebChromeClient());
  
  
          //webview.loadUrl("file:///android_asset/test.html");
  
          /*String str = "&lt;books&gt;" +
                  "&lt;book title=\"A Tale of Two Cities\"/&gt;" +
                  "&lt;book title=\"1984\"/&gt;" +
                  "&lt;/books&gt;";*/
  
  
  
  
          webview.loadUrl("file:///android_asset/test.html");
          webview.loadUrl("javascript:myFunction()");
          //webview.loadUrl("javascript:myFunction("+str+")");
  
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }    
  }
  </code></pre>
  
  <p>test.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;script type="text/javascript" src="marknote.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  function myFunction()
  {
  var str = '&lt;books&gt;&lt;book&gt;&lt;/book&gt;&lt;/books&gt;';
  var parser = new marknote.Parser();
  var doc = parser.parse(str);
  
  var bookEls = doc.getRootElement().getChildElements();
  
      for (var i=0; i&lt;bookEls.length; i++) {
          var bookEl = bookEls[i];
  
          alert("Element name is " + bookEl.getName());
      }
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have seen this error occurred when I am using <code>webview.loadUrl("javascript:myFunction()");</code>. I want to pass a xml string from java and parse it into javascript. Please help me to find a solution.</p>