的WebView造成的第二个活动错误 [英] WebView causing errors on second activity

查看:118
本文介绍了的WebView造成的第二个活动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,工作正常,当我有它在我的主要活动:

 的WebView web视图=(web视图)findViewById(R.id.iQuestionWebView);
    webView.loadDataWithBaseURL(NULL,测试,text / html的,UTF-8,NULL);
 

凡的WebView布局只是看起来是这样的:

 <的WebView
    机器人:ID =@ + ID / iQuestionWebView
    机器人:layout_width =match_parent
    机器人:layout_height =200dp/>
 

但是,如果我把布局和code我的第二个活动(一个简单的LinearLayout),我得到以下错误:

  

netstack:LIB_MGR - 错误加载LIB libdnshostprio.so

     

netstack:STAT_HUB - 无法加载插件:libdnshostprio.so

     

netstack:LIB_MGR - 错误加载LIB spl_proc_plugin.so

     

netstack:STAT_HUB - 无法加载插件:spl_proc_plugin.so

     

netstack:LIB_MGR - 错误加载LIB pp_proc_plugin.so

     

netstack:STAT_HUB - 无法加载插件:pp_proc_plugin.so

     

netstack:STAT_HUB - 不支持应用程序com.ms.wvtest

     

E / cutils追踪(11142):错误打开跟踪文件:权限被拒绝(13)

正如你所看到的,code是非常基本的 - 一个简单的按钮,启动第二个活动:

MainActivity.java

 公共类MainActivity扩展活动
{
    @覆盖
    保护无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        最终按钮startQuiz =(按钮)findViewById(R.id.iMainStartQuizButton);
        startQuiz.setOnClickListener(新View.OnClickListener()
        {
            @覆盖
            公共无效的onClick(视图v)
            {
                意向意图=新的意图(MainActivity.this,Quiz.class);
                startActivity(意向);
            }
        });
    }
}
 

Quiz.java

 公共类测验扩展活动
{
    @覆盖
    保护无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.quiz);

        的WebView web视图=(web视图)findViewById(R.id.iQuestionWebView);
        webView.loadDataWithBaseURL(NULL,测试,text / html的,UTF-8,NULL);
    }
}
 

我会AP preciate,如果有人可以指出我的错误的原因。预先感谢您的帮助!

编辑:作为请求quiz.xml和清单:

quiz.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    <的WebView
        机器人:ID =@ + ID / iQuestionWebView
        机器人:layout_width =match_parent
        机器人:layout_height =200dp/>

< / LinearLayout中>
 

AndroidManifest.xml中

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.ms.studycards
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =11
        机器人:targetSdkVersion =18/>

    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ l_app_name
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名称=com.ms.studycards.MainActivity
            机器人:标签=@字符串/ l_setup_title>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名称=com.ms.studycards.Quiz
            机器人:标签=@字符串/ l_quiz_title
            机器人:parentActivityName =com.ms.studycards.MainActivity>
        < /活性GT;
    < /用途>

< /舱单>
 

解决方案

下面是我如何解决这个问题,虽然我只测试我的应用程序的设备上(模拟器太慢)。

  1. 在清单文件,添加Internet的权限:

     使用-权限的Andr​​oid:名称=android.permission.INTERNET对
     

  2. 在你的WebView(所以在Quiz.java),您需要启用javascript:

      webView.getSettings()setJavaScriptEnabled(真)。
     

在我的情况下,这2个东西摆脱这个问题,并显示在设备中的web视图的内容(YouTube视频在我的情况)。

I have the following code which works fine when I have it in my main Activity:

    WebView webView = (WebView)findViewById(R.id.iQuestionWebView);
    webView.loadDataWithBaseURL(null, "test", "text/html", "utf-8", null);

Where the WebView layout simply looks like this:

<WebView
    android:id="@+id/iQuestionWebView"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>

But if I put the layout and the code to my second Activity (a simple LinearLayout), I get the following errors:

netstack: LIB_MGR - Error loading lib libdnshostprio.so

netstack: STAT_HUB - Failed to load plugin: libdnshostprio.so

netstack: LIB_MGR - Error loading lib spl_proc_plugin.so

netstack: STAT_HUB - Failed to load plugin: spl_proc_plugin.so

netstack: LIB_MGR - Error loading lib pp_proc_plugin.so

netstack: STAT_HUB - Failed to load plugin: pp_proc_plugin.so

netstack: STAT_HUB - App com.ms.wvtest isn't supported

E/cutils-trace(11142): Error opening trace file: Permission denied (13)

As you can see, the code is very basic - a simple button that starts the second Activity:

MainActivity.java

public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button startQuiz = (Button)findViewById(R.id.iMainStartQuizButton);
        startQuiz.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                Intent intent = new Intent(MainActivity.this, Quiz.class);
                startActivity(intent);
            }
        });
    }
}

Quiz.java

public class Quiz extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.quiz);

        WebView webView = (WebView)findViewById(R.id.iQuestionWebView);
        webView.loadDataWithBaseURL(null, "test", "text/html", "utf-8", null);
    }
}

I would appreciate it if someone could point me to the cause of the error. Thank you in advance for your help!

Edit: As requested quiz.xml and the manifest:

quiz.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/iQuestionWebView"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ms.studycards"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/l_app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ms.studycards.MainActivity"
            android:label="@string/l_setup_title" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.ms.studycards.Quiz"
            android:label="@string/l_quiz_title"
            android:parentActivityName="com.ms.studycards.MainActivity">
        </activity>
    </application>

</manifest>

解决方案

Here's how I solved this issue, although I only test my apps on a device (the simulator is too slow).

  1. In the manifest file, add the internet permission:

    uses-permission android:name="android.permission.INTERNET"
    

  2. In your webview (so in Quiz.java), you need to enable javascript:

    webView.getSettings().setJavaScriptEnabled(true);
    

In my case, these 2 things get rid of the problem and display the content (youtube video in my case) in the webview in the device.

这篇关于的WebView造成的第二个活动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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