指定的孩子已经有父母。用于webview链接if else的Android webview错误

时间:2017-04-11 09:01:09

标签: android webview

public class Site extends Activity {
    WebView mWebview;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.site);

        mWebview = (WebView) findViewById(R.id.webview);
        mWebview.getSettings().setJavaScriptEnabled(true);

        final Activity activity = this;
        Intent IntentGM= getIntent();
        Bundle b = IntentGM.getExtras();
        String GMget =(String) b.get("GameMania");
        String MGget =(String) b.get("MediaGames");
        String BCget =(String) b.get("BolCom");
        String webUrl = mWebview.getUrl();


        final Activity Site = this;
        mWebview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                // Activities and WebViews measure progress with different scales.
                // The progress meter will automatically disappear when we reach 100%
                Site.setProgress(progress * 1000);
            }
        });
        mWebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(Site, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            }
        });

        if (GMget != null && GMget.length() > 4)
        {
            String Link = "http://www.gamemania.nl";
            mWebview.setWebViewClient(new WebViewClient()
            {
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                    Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
                }
            });
            mWebview .loadUrl(Link);
            setContentView(mWebview );
        }
        else if (MGget != null && MGget.length() > 4)
        {
            String Link = "http://www.mediamarkt.nl/games";
            mWebview.setWebViewClient(new WebViewClient()
            {
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                    Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
                }
            });
            mWebview .loadUrl(Link);
            setContentView(mWebview );
        }
        else if (BCget != null && BCget.length() > 4)
        {
            String Link = "http://www.bol.com/games";
            mWebview.setWebViewClient(new WebViewClient()
            {
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                    Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
                }
            });
            mWebview .loadUrl(Link);
            setContentView(mWebview );
        }
    }
}

我认为这是我的if-else查询,但我不知道要改变什么才能让它发挥作用。 当我想从按钮打开此活动时,我得到此错误,我必须在此webview中访问Bol.com。 我想要的是一个全屏幕webview的活动,还有用于分享网址的按钮,返回& webview-screen上方的其他选项。

0 个答案:

没有答案