1

我在使用以下URL加载 webview 时遇到问题:

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

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

但两者都在 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/");
    }
}
4

1 回答 1

5

我真的不知道为什么(你可以做更多的研究),但把它放进去似乎让它起作用了!

webSettings.setDomStorageEnabled(true);

我在这里发现:

错误/Web 控制台:未捕获的类型错误:无法在 http://m.youtube.com/:844 调用 null 方法“getItem”

于 2012-05-22T14:50:22.280 回答