无法加载使用的WebView网页中的Andr​​oid加载、网页、oid、WebView

由网友(い 还是原来那个我)分享简介:我最近采取了Android的发展,我一直在寻找使用的WebView显示网页。我拿起从被赋予在谷歌网站,出于某种原因,仿真器不停地说页面不可用样品。我搜索的计算器,发现有关WebViewClient链接。我想,也不过没有运气,我都检查过多次有关Internet的权限和那里的清单条目。作为测试我跑了仿真器中可用的浏览器,果...

我最近采取了Android的发展,我一直在寻找使用的WebView显示网页。我拿起从被赋予在谷歌网站,出于某种原因,仿真器不停地说页面不可用样品。我搜索的计算器,发现有关WebViewClient链接。我想,也不过没有运气,我都检查过多次有关Internet的权限和那里的清单条目。作为测试我跑了仿真器中可用的浏览器,果然我的防火墙弹出是否允许它访问与否的问题。在弹出从来没有向我走来时,我是从程序运行它。在code,我有是什么东西有谷歌的网页

  mWebView =(web视图)findViewById(R.id.webview);
    mWebView.getSettings()setJavaScriptEnabled(真)。
    mWebView.loadUrl(http://www.google.com);
    mWebView.setWebViewClient(新HelloWebViewClient());

    私有类HelloWebViewClient扩展WebViewClient {
    @覆盖
    公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
        view.loadUrl(URL);
        返回true;
    }
 

我试图直接加载简单的HTML使用loadData它工作得很好。我在迷失,发生了什么以及如何可以解决的。我想在这个AP preciate任何帮助。

在这里添加Android清单

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

<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。HelloWebView
              机器人:标签=@字符串/ APP_NAME
              机器人:主题=@安卓风格/ Theme.NoTitleBar>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
 <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
< /用途>
< /舱单>
 

要检查,如果它只是一个web视图啄,我尝试访问使用HTTPGET和HTT presonse类的互联网,并得到了同样的问题,在code无法连接到指定的站点。它没有说明以下

  

  05-10 00:37:53.191:WARN / System.err的(294):的java.net.UnknownHostException:feeds.feedburner.com
05-10 00:37:53.230:WARN / System.err的(294):在java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-10 00:37:53.230:WARN / System.err的(294):在java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-10 00:37:53.230:WARN / System.err的(294):在java.net.InetAddress.getAllByName(InetAddress.java:242)
05-10 00:37:53.250:WARN / System.err的(294):在org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-10 00:37:53.250:WARN / System.err的(294):在org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-10 00:37:53.250:WARN / System.err的(294):在org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-10 00:37:53.271:WARN / System.err的(294):在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-10 00:37:53.271:WARN / System.err的(294):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-10 00:37:53.280:WARN / System.err的(294):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-10 00:37:53.291:WARN / System.err的(294):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-10 00:37:53.301:WARN / System.err的(294):在com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:43)
05-10 00:37:53.301:WARN / System.err的(294):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:37:53.309:WARN / System.err的(294):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:37:53.322:WARN / System.err的(294):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:37:53.330:WARN / System.err的(294):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
05-10 00:37:53.340:WARN / System.err的(294):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
05-10 00:37:53.350:WARN / System.err的(294):在android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:37:53.350:WARN / System.err的(294):在android.os.Looper.loop(Looper.java:123)
05-10 00:37:53.361:WARN / System.err的(294):在android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:37:53.361:WARN / System.err的(294):在java.lang.reflect.Method.invokeNative(本机方法)
05-10 00:37:53.372:WARN / System.err的(294):在java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:37:53.380:WARN / System.err的(294):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:37:53.380:WARN / System.err的(294):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:37:53.401:WARN / System.err的(294):在dalvik.system.NativeStart.main(本机方法)
05-10 00:37:56.773:WARN / ActivityManager(58):启动超时已过期,放弃唤醒锁!
05-10 00:37:58.083:WARN / ActivityManager(58):活动空闲超时时间为HistoryRecord {44fc9108 com.example.hellowebview / .HelloWebView}
05-10 00:38:06.300:DEBUG / KeyguardViewMediator(58):pokeWakelock(5000)
05-10 00:38:06.651:信息/ ARMAssembler(58):产生scanline__00000077:03545404_00000004_00000000 [47 IPP](67英寸),在[0x3724c8:0x3725d4在7266287 NS
05-10 00:38:06.720:信息/ ARMAssembler(58):产生scanline__00000177:03515104_00001001_00000000 [91 IPP(114英寸),在[0x371380:0x371548]在1486222 NS
05-10 00:38:30.430:DEBUG / AndroidRuntime(294):关闭虚拟机
05-10 00:38:30.430:WARN / dalvikvm(294):主题ID = 1:螺纹退出与未捕获的异常(组= 0x4001d800)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):致命异常:主要
05-10 00:38:30.752:ERROR / AndroidRuntime(294):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.example.hellowebview / com.example.hellowebview.HelloWebView}:显示java.lang.NullPointerException
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.os.Looper.loop(Looper.java:123)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在java.lang.reflect.Method.invokeNative(本机方法)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在dalvik.system.NativeStart.main(本机方法)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):由:显示java.lang.NullPointerException
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:51)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:38:30.752:ERROR / AndroidRuntime(294):11 ...更多
 

明白了。出于某种原因,在权限设置的顺序是相当重要的。我改变了我的许可清单文件设定的顺序和它的工作。下面是修改后的清单

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.hellowebview
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =8/>
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
<活动机器人:名称=。HelloWebView
          机器人:标签=@字符串/ APP_NAME
          机器人:主题=@安卓风格/ Theme.NoTitleBar>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.MAIN/>
        <类机器人:名称=android.intent.category.LAUNCHER/>
    &所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
 

我不知道什么是这样做的意义,但就AP preciate如果有人能详细阐述。

解决方案

明白了。出于某种原因,在权限设置的顺序是相当重要的。我改变了我的许可清单文件设定的顺序和它的工作。下面是修改后的清单

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.example.hellowebview
  安卓版code =1
  机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =8/>
 <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。HelloWebView
              机器人:标签=@字符串/ APP_NAME
              机器人:主题=@安卓风格/ Theme.NoTitleBar>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>
< /舱单>
 

I have recently taken up Android Development and I was looking to using the WebView display webpages. I picked up from the sample that was given on Google site and for some reason the emulator kept saying page was not available. I searched in StackOverflow and found links relating to WebViewClient. I tried that also but no luck there, I have checked multiple times about the manifest entry for internet permission and its there. As a test I ran the browser available within the emulator and sure enough my firewall popped up a question on whether to allow it access or not. The pop up never came to me when I was running it from program. The code that I have is what is there Google pages

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("http://www.google.com");  
    mWebView.setWebViewClient(new HelloWebViewClient());

    private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

I tried loading simple html directly using loadData and it worked fine. I am at loss as to what is happening and how this can be resolved. I would appreciate any help on this.

Adding the Android Manifest here

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.hellowebview"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".HelloWebView"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>     
 <uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>

To check if its just a WebView thingy, I tried accessing the internet using httpGet and httpResonse classes and got the same problem, the code was not able to connect to the given site. It failed stating the below

05-10 00:37:53.191: WARN/System.err(294): java.net.UnknownHostException: feeds.feedburner.com
05-10 00:37:53.230: WARN/System.err(294):     at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-10 00:37:53.230: WARN/System.err(294):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-10 00:37:53.230: WARN/System.err(294):     at java.net.InetAddress.getAllByName(InetAddress.java:242)
05-10 00:37:53.250: WARN/System.err(294):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-10 00:37:53.250: WARN/System.err(294):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-10 00:37:53.250: WARN/System.err(294):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-10 00:37:53.271: WARN/System.err(294):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-10 00:37:53.271: WARN/System.err(294):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-10 00:37:53.280: WARN/System.err(294):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-10 00:37:53.291: WARN/System.err(294):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-10 00:37:53.301: WARN/System.err(294):     at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:43)
05-10 00:37:53.301: WARN/System.err(294):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:37:53.309: WARN/System.err(294):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:37:53.322: WARN/System.err(294):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:37:53.330: WARN/System.err(294):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:37:53.340: WARN/System.err(294):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:37:53.350: WARN/System.err(294):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:37:53.350: WARN/System.err(294):     at android.os.Looper.loop(Looper.java:123)
05-10 00:37:53.361: WARN/System.err(294):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:37:53.361: WARN/System.err(294):     at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:37:53.372: WARN/System.err(294):     at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:37:53.380: WARN/System.err(294):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:37:53.380: WARN/System.err(294):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:37:53.401: WARN/System.err(294):     at dalvik.system.NativeStart.main(Native Method)
05-10 00:37:56.773: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
05-10 00:37:58.083: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44fc9108 com.example.hellowebview/.HelloWebView}
05-10 00:38:06.300: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000)
05-10 00:38:06.651: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3724c8:0x3725d4] in 7266287 ns
05-10 00:38:06.720: INFO/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x371380:0x371548] in 1486222 ns
05-10 00:38:30.430: DEBUG/AndroidRuntime(294): Shutting down VM
05-10 00:38:30.430: WARN/dalvikvm(294): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): FATAL EXCEPTION: main
05-10 00:38:30.752: ERROR/AndroidRuntime(294): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellowebview/com.example.hellowebview.HelloWebView}: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.os.Looper.loop(Looper.java:123)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at dalvik.system.NativeStart.main(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): Caused by: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:51)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294):     ... 11 more

Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloWebView"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>     
</application>
</manifest>

I am not sure what is the significance of this but would appreciate if anyone could elaborate.

解决方案

Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.hellowebview"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
 <uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".HelloWebView"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>     
</application>
</manifest>

阅读全文

相关推荐

最新文章