Android的web视图不加载网址 [英] Android web view is not loading the URL

查看:198
本文介绍了Android的web视图不加载网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网址上装载的WebView一个问题:


  1. http://www.walmart.com/


  2. http://mobile.walmart.com/


但都显示的WebView一个空白页。

下面我附上源$ C ​​$ C。我如何来解决这一问题的?

来源:

 进口android.app.Activity;
进口android.content.Context;
进口android.os.Bundle;
进口android.view.Window;
进口android.webkit.WebChromeClient;
进口android.webkit.WebSettings;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;
进口android.widget.Button;公共类WEBVIEW_ITSELF延伸活动{    的WebView homeWeb;
    按钮btnPlay;    最后活动活动=这一点;
    静态上下文mContext;    公共布尔orandationChange = TRUE;    @覆盖
    保护无效的onPause(){
        super.onPause();        orandationChange = FALSE;
    }    字符串为urlChange;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);
        。this.getWindow()requestFeature(Window.FEATURE_PROGRESS);
        的setContentView(R.layout.i_webview);        mContext =这一点;        homeWeb =(的WebView)findViewById(R.id.website_webview);
        homeWeb.getSettings()setJavaScriptEnabled(真)。
        。homeWeb.getSettings()setSupportZoom(真); //网页上缩放控制(你)        homeWeb.clearHistory();
        homeWeb.clearFormData();
        homeWeb.clearCache(真);        WebSettings webSettings = homeWeb.getSettings();
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);        homeWeb.setWebChromeClient(新WebChromeClient(){
            公共无效onProgressChanged(的WebView观点,诠释进度){
                activity.setTitle(正在加载...);
                activity.setProgress(进度* 100);                如果(==进度100)
                    activity.setTitle(R.string.app_name); //为了使这个你
                                                          //不要设置
                                                          //机器人:主题=@安卓风格/ Theme.Black.NoTitleBar
                                                          // manifest文件中。
            }
        });        homeWeb.setWebViewClient(新WebViewClient(){
            公共无效onReceivedError(的WebView观点,诠释错误code,
                    描述字符串,字符串failingUrl){                的System.out.println(failingUrl+ failingUrl);
                的System.out.println(说明+说明);
                的System.out.println(错误code+错误code);                //处理错误
            }            @覆盖
            公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){                view.loadUrl(URL);                返回false;
            }
        });        homeWeb.loadUrl(http://mobile.walmart.com/);
    }
}


解决方案

我真的不知道为什么(你可以做一些更多的研究),但把这个在似乎使其工作!

  webSettings.setDomStorageEnabled(真);

我发现在这里:

<一个href=\"http://stackoverflow.com/questions/5822256/error-web-console-uncaught-typeerror-cannot-call-method-getitem-of-null-at-h\">ERROR/Web控制台:未捕获类型错误:无法调用空的方法'的getItem在http://m.youtube.com/:844

I have a problem on loading webview with the following URLs:

  1. http://www.walmart.com/

  2. http://mobile.walmart.com/

But both are showing an empty page in webview.

Here I have attached the source code. How do I come out of this problem?

Source:

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class WEBVIEW_ITSELF extends Activity {

    WebView homeWeb;
    Button btnPlay;

    final Activity activity = this;
    static Context mContext;

    public boolean orandationChange = true;

    @Override
    protected void onPause() {
        super.onPause();

        orandationChange = false;
    }

    String urlchange;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.i_webview);

        mContext = this;

        homeWeb = (WebView) findViewById(R.id.website_webview);
        homeWeb.getSettings().setJavaScriptEnabled(true);
        homeWeb.getSettings().setSupportZoom(true); // Zoom control on web (You)

        homeWeb.clearHistory();
        homeWeb.clearFormData();
        homeWeb.clearCache(true);

        WebSettings webSettings = homeWeb.getSettings();
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

        homeWeb.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if (progress == 100)
                    activity.setTitle(R.string.app_name); // To enable this you
                                                          // should not set
                                                          // android:theme="@android:style/Theme.Black.NoTitleBar"
                                                          // in the manifest file.
            }
        });

        homeWeb.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {

                System.out.println(" failingUrl " + failingUrl);
                System.out.println(" description " + description);
                System.out.println(" errorCode " + errorCode);

                // Handle the error
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                view.loadUrl(url);

                return false;
            }
        });

        homeWeb.loadUrl("http://mobile.walmart.com/");
    }
}

解决方案

I'm really not sure why (you can do some more research), but putting this in seems to make it work!

webSettings.setDomStorageEnabled(true);

I found that here:

ERROR/Web Console: Uncaught TypeError: Cannot call method 'getItem' of null at http://m.youtube.com/:844

这篇关于Android的web视图不加载网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆