Android WebView don’t show the content of the website

I’m a noob in programming and I’m doing a WebView from a tracking website. The problem is, when I type the tracking code in the WebView the site doesn’t show anything, I will show to you in next images:

Here is my code:

public class MainActivity extends AppCompatActivity {
private WebView webview;
private static final String TAG = "Main";
private ProgressDialog progressBar;

protected void onCreate(Bundle savedInstanceState) {

    this.webview = (WebView)findViewById(;

    WebSettings settings = webview.getSettings();
    webview.addJavascriptInterface(new WebAppInterface(this), "android");

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    progressBar =, "WebView Example", "Loading...");

    webview.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            Log.i(TAG, "Processing webview url click...");
            return true;
        public void onPageFinished(WebView view, String url){
            Log.i(TAG, "Finished loading url: " +url);
            if (progressBar.isShowing()){
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
            Log.e(TAG, "Error: " + description);
            Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
public class WebAppInterface{
    Context mContext;

    WebAppInterface(Context c){
        mContext = c;

    public void showToast(String toast){
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(, menu);
    return true;
public boolean onOptionsItemSelected(MenuItem item){
    switch (item.getItemId()){

            return true;
    return super.onOptionsItemSelected(item);
public boolean onKeyDown(int keyCode, KeyEvent event){
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()){
        return true;
    return super.onKeyDown(keyCode, event);

Please help me.


The problem is you haven’t enabled LocalStorage for your WebView. If you use Chrome to inspect your WebView via developer tools, you will notice that you have an error. Specifically main.js?v=1:373 Uncaught TypeError: Cannot read property 'length' of null

Why is this? If you look at that line of code in main.js you will see that the script is accessing length of localStorage. It will crash the script because you can not access a property of an undefined variable. localStorage is undefined in a WebView by default, because DomStorage is not enabled.

To fix this. Enable LocalStorage for your WebView add the line:


Where settings is the WebView‘s WebSettings object.

After doing this everything works as you should expect!

Leave a Reply

Your email address will not be published. Required fields are marked *