Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

470
Views
Uncaught ReferenceError: for JS library on Android Project

Trying to create a demo app using the VAST Client JS library in my Android Project.

For this, I have downloaded the library's pre-bundled version

JS library document

and put it in the assets folder.

Assets folder

Besides that, I've also created an HTML file that basically calls the JS functions of the library.

< !DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script src='file:///android_asset/vast-client-browser-min.js'></script>
<script>
 // Get the VAST Url from the Java class
 const tagURL = window.MyHandler.getVASTUrl();
 
 const vastClient = new VAST.VASTClient();

 vastClient.get(tagURL)
 .then(res => {
    // notify my Java class
    window.MyHandler.onResponse('hey');
 }).catch(err => {
    // notify my Java class
     window.MyHandler.onError('heyy');
 });
</script>
</head>
<html>
<body>
</body>
</html>

On the Java side, I call my HTML file

    // initialize webview
    WebView.setWebContentsDebuggingEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    
    // add javascript interface to notify my java class from the JS side.
    webView.addJavascriptInterface(new JavaScriptInterface(this, webView), "MyHandler");
    
    // Load the HTML file
    webView.loadUrl("file:///android_asset/vast_client_handler.html");

However, when I run the app, I get this;

I/chromium: [INFO:CONSOLE(17)] "Uncaught ReferenceError: VASTClient is not defined", source: file:///android_asset/vast_client_handler.html (17)

what could I be missing? Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your whole HTML document is wrong.

  • First, you should start with the <html> tag and not the <head> tag.
  • The < !DOCTYPE html> has a space after the first < character so it doesn't get parsed properly
  • You have a closing tag after the script, but the script should be inside
  • This is just a suggestion - but if you're loading a resource in the head, you should properly put the script that uses it inside the body so that you won't have race conditions (<head> content loads before the <body>)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!