title: I/chromium﹕ [INFO:CONSOLE(1)] "Uncaught ReferenceError: callJS is not defined"
body: <p>I'm getting the following error in Android Studio logcat:
  I/chromium﹕ [INFO:CONSOLE(1)] "Uncaught ReferenceError: callJS is not defined"</p>
  
  <p>I have researched on stackoverflow and tried the suggested answers on similar post with no luck. <a href="https://stackoverflow.com/questions/22281195/uncaught-referenceerror-jquery-is-not-defined-android-chromium">here</a></p>
  
  <p>I'm trying to execute javascript from a local html file that is loaded into a WebChromeClient by clicking on a android button.  The code is taken from the Chapter 10 example in The Pragmatic Programmers "Hello Android Introducing Google's Mobile development Platform" fourth Edition book.</p>
  
  <p>index.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script language="JavaScript"&gt;
          function callJS(arg){
              document.getElementById('replaceMe').innerHTML = arg;
          {
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;WebView&lt;/h2&gt;
      &lt;p&gt;
          &lt;a href="#" onClick="window.alert('Alert from Javascript')"&gt;Display JavaScript alert&lt;/a&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;a href="#" onClick="window.android.callAndroid('Hello from Browser')"&gt;Call Android from JavaScript&lt;/a&gt;
      &lt;/p&gt;
      &lt;p id="replaceMe"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.os.Handler;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.webkit.JavascriptInterface;
  import android.webkit.JsResult;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
     private static final String TAG = "LocalBrowser";
     private final Handler handler = new Handler();
     private WebView webView;
     private TextView textView;
     private Button button;
  
     /** Object exposed to JavaScript */
     private class AndroidBridge {
        @JavascriptInterface // Required in Android 4.2+
        public void callAndroid(final String arg) { // must be final
           handler.post(new Runnable() {
              public void run() {
                 Log.d(TAG, "callAndroid(" + arg + ")");
                 textView.setText(arg);
              }
           });
        }
     }
  
     @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
  
        // Find the Android controls on the screen
        webView = (WebView) findViewById(R.id.web_view);
        textView = (TextView) findViewById(R.id.text_view);
        button = (Button) findViewById(R.id.button);
        // Rest of onCreate follows...
  
        // Turn on JavaScript in the embedded browser
        webView.getSettings().setJavaScriptEnabled(true);
  
        // Expose a Java object to JavaScript in the browser
        webView.addJavascriptInterface(new AndroidBridge(),
              "android");
  
        // Set up a function to be called when JavaScript tries
        // to open an alert window
        webView.setWebChromeClient(new WebChromeClient() {
           @Override
           public boolean onJsAlert(final WebView view,
                 final String url, final String message,
                 JsResult result) {
              Log.d(TAG, "onJsAlert(" + view + ", " + url + ", "
                    + message + ", " + result + ")");
              Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
              result.confirm();
              return true; // I handled it
           }
        });
  
        // Load the web page from a local asset
        webView.loadUrl("file:///android_asset/index.html");
  
        // This function will be called when the user presses the
        // button on the Android side
        button.setOnClickListener(new OnClickListener() {
           public void onClick(View view) {
              Log.d(TAG, "onClick(" + view + ")");
              if (android.os.Build.VERSION.SDK_INT &lt; 19) {
                 webView.loadUrl("javascript:callJS('Hello from Android')");
              }else{
                 webView.evaluateJavascript("javascript:callJS('Hello from Android')", null);
              }
           }
        });
     }
  }
  </code></pre>
  
  <p>activity_main</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;WebView
          android:id="@+id/web_view"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1.0"/&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:layout_weight="1.0"
          android:padding="5sp"&gt;
  
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="24sp"
              android:text="@string/textView"/&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/button"
              android:text="@string/call_javascript_from_android"
              android:textSize="18sp"/&gt;
  
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/text_view"
              android:textSize="18sp"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Any help is greatly appreciated! Thanks in advance!</p>