Android网页视图未加载网址

时间:2012-05-22 13:17:53

标签: android webview

我在使用以下URLs

加载webview时遇到问题
  1. http://www.walmart.com/

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

  3. 但两者都在webview中显示一个空白页面。

    这里我附上了源代码。我该如何摆脱这个问题?

    来源:

    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/");
        }
    }
    

1 个答案:

答案 0 :(得分:5)

我真的不确定为什么(你可以做更多的研究),但是把它放进去似乎可以使它工作!

webSettings.setDomStorageEnabled(true);

我在这里找到了:

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