WebView.getUrl() returns null


I have an issue with Webview. I'm programming my own WebChromeClient class overriding onProgressChanged method because I want to show the page when it finishes loading and then, to hide the splash screen. As I just want it to happen with a specific url, I compare the actual WebView url with a specific string, but there is a problem, I get a null pointer when webview.getUrl() method is called and my application finishes. This is the code:

private class MyWebChromeClient extends WebChromeClient { @Override public void onProgressChanged (WebView webview, int newProgress) { super.onProgressChanged(webview,newProgress); if(webview.equals(w1) && newProgress == 100 && webview.getUrl().startsWith("https://ssl.facebook.com/login.php")) { webview.setVisibility(WebView.VISIBLE); ImageView imageview = (ImageView)findViewById(R.id.ivsplash); imageview.setVisibility(ImageView.GONE); ProgressBar progressbar = (ProgressBar)findViewById(R.id.pbsplash); progressbar.setVisibility(ProgressBar.GONE); } } }

I do this for avoid the webview takes three or four seconds to render the page, but it doesn't work. The code I used before was:

private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView webview, String url) { super.shouldOverrideUrlLoading(webview, url); webview.loadUrl(url); return true; } @Override public void onPageFinished(WebView webview, String url) { if(url.startsWith("https://ssl.facebook.com/login.php")) { webview.setVisibility(WebView.VISIBLE); ImageView imageview = (ImageView)findViewById(R.id.ivsplash); imageview.setVisibility(ImageView.GONE); ProgressBar progressbar = (ProgressBar)findViewById(R.id.pbsplash); progressbar.setVisibility(ProgressBar.GONE); } } }



Not sure if this is possible with WebChromeClient, but I was able to do this using

WebViewClient and overloading onLoadResource, onReceivedError and onPageFinished

This is what I've done

onLoadResource mwebview.setVisibility(View.GONE); onReceivedError mwebview.setVisibility(View.VISIBLE); onPageFinished mwebview.setVisibility(View.VISIBLE);

and intially in XML the webview is set as GONE


I too use it for Facebook and works fine.


  • android how get url in page loaded- loading
  • Error getting audio input device sample rate: '!obj'
  • Android WebView enters unrecoverable state if executed JavaScript enters infinite loop
  • android 2.2 WebView and WebViewClient RTSP problem
  • Use shared WKWebViewCookies for a request
  • WebView: webpage not available but I load it from an html string
  • Phonegap Android App, open links within app?
  • input type=“file” accept=“image/*” doesn't work in phone gap?
  • Why is OpenID Connect considered mobile friendly compared to SAML
  • setContentView() is not enough to switch between layouts?
  • Cut the background to expose the layer below
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Object and struct member access and address offset calculation
  • How to assign byte[] as a pointer in C#
  • how to avoid repetitive constructor in children
  • Highlight and Bold text in JTextPane
  • how to do an event when i swipe from fragment to the other
  • Update CALayer sublayers immediately
  • JFileChooser in front of fullscreen Swing application
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • C# - Serializing and deserializing static member
  • output of program is not same as passed argument
  • Sending data from AppleScript to FileMaker records
  • Javascript + PHP Encryption with pidCrypt
  • Akka Routing: Reply's send to router ends up as dead letters
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Getting Messege Twice Using IMvxMessenger
  • LevelDB C iterator
  • How can I remove ASP.NET Designer.cs files?
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • How can i traverse a binary tree from right to left in java?
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?