无法在WebView中加载网址 [英] Unable to load url in webview

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

问题描述

我正在尝试在Web视图中加载URL,但是我不断收到错误消息.(请参见下文)

I'm trying to load a URL in a webview but I keep getting an error. (see below)

这是应该在启动时加载URL的代码:

this is the code that should load the URL at startup:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }

    WebView mywebview1;

       mywebview1 = (WebView)findViewById(R.id.myownwebview);
       mywebview1.loadUrl("http://www.mad-sharky.com");
}

我的XML文件中有一个Web视图,其ID为"myownwebview".每当我启动项目时,我都会收到如图所示的错误消息:

I have a webview in my XML file with id "myownwebview". Whenever i start the projecti get the error message shown in the picture:

我进行了大量搜索,发现的大多数答案都表明该URL在创建之前已写入视图,因此会引发异常.应该在"seContentView"之后.但就我而言,它在 setContentView 之后,所以我找不到造成它的原因.

I searched a lot and most of the answers I found tell that the URL is written to the view before it is created and therefore it throws an exception. It is supposed to be after "seContentView". But in my case it is after setContentView so I can't find what is causing it.

调试屏幕图像:

推荐答案

该片段事务可能导致异常,因此请注释以下代码:

probably the fragment transaction is causing the exception, so comment this code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   /* if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }*/


    WebView mywebview1;

       mywebview1 = (WebView)findViewById(R.id.myownwebview);
       mywebview1.loadUrl("http://www.mad-sharky.com");


}

或从 PlaceholderFragment

这篇关于无法在WebView中加载网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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