I am trying to load a local HTML file in my Android application's webview. The HTML file references a local copy of jquerymobile.js
. My problem
is when the application is launched, the following error is thrown:
TypeError 'undefined' is not an object (evaluating $ event)
This happens even without any code written that uses the jquery lib
.This error does not happen when I load the jquery library from their CDN
.
Any ideas as to what I am doing wrong? Thanks for your time.
Added code for more clarity:
This is where the WebView
loads the url
try {
//this reads the jquerymobile as a string
jmobile = readFileAsString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wview1.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
//Required functionality here
return super.onJsAlert(view, url, message, result);
}
});
wview1.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(wview1, url);
wview1.loadUrl("javascript:"+jmobile);
// do your stuff here
}
});
wview1.loadUrl("file:///android_asset/html/index.html");
The following works
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
But if I change the script src to a local copy of jquery.mobile-1.1.1.min.js, I get the type error