Android Webview 中的 loadUrl() 因 net::ERR_CACHE_MISS 而失败 [英] loadUrl() in Android Webview fails with net::ERR_CACHE_MISS
本文介绍了Android Webview 中的 loadUrl() 因 net::ERR_CACHE_MISS 而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 android studio 工作.我在主要活动中使用了 webview.当我运行我的项目时,它会给出一个错误,例如......http://www.google.com 上的网页a> 无法加载,因为:net::ERR_CACHE_MISS".请看我的代码:在清单中:
I am working in android studio.I have used webview in main activity. When I run my project then it gives an error like... "The webpage at http://www.google.com could not be loaded because: net::ERR_CACHE_MISS". Please see my code: In manifest:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".defaultActivity"
android:label="@string/app_name"
>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.android.permission.ACCESS_NETWORK_STATE"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
活动中:
WebView _taskOrganizerView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_default);
_taskOrganizerView = (WebView)findViewById(R.id.wvTskOrg);
_taskOrganizerView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {
_taskOrganizerView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
_taskOrganizerView.loadUrl("http://www.google.com");
_taskOrganizerView.setWebViewClient(new WebViewClient() );
}
在布局中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".defaultActivity">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wvTskOrg"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
推荐答案
今天遇到同样的问题,最后发现忘记在 AndroidManifest.xml 文件中添加权限通知.添加
I face the same issue today, and at last I found that I just forget to add permission annoncement in AndroidManifest.xml file. It just went fine after I add
<uses-permission android:name="android.permission.INTERNET"/>
在 AndroidManifest.xml 中
in AndroidManifest.xml
这篇关于Android Webview 中的 loadUrl() 因 net::ERR_CACHE_MISS 而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文