无法加载URL中的WebView(机器人) [英] Unable to load url in webview (android)

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

问题描述

我想在一个的WebView加载一个URL,但我不断收到一个错误。 (见下文)

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

这是在code,它在启动时加载的网址:

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文件中的WebView 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:

我搜索了很多,最让我找到了答案告诉大家,网址写入视图创建之前,因此它抛出一个异常。它被认为是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. It is my first app so bare with me if it is a basic question.

感谢

更新

调试屏幕图像:

推荐答案

大概是片段的交易导致了异常,所以这个评论code:

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


}

或加载的URL到从web视图的 PlaceholderFragment

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

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