我在android studio工作。我在主要活动中使用了webview。当我运行我的项目时,它会给出一个错误,例如......“无法加载http://www.google.com的网页,因为:net :: ERR_CACHE_MISS”。 请看我的代码: 在清单中:
SELECT col1
,CASE WHEN CAST(start_dt AS DATE) = b.cal_dt THEN start_dt
WHEN CAST(end_dt AS DATE) = b.cal_dt THEN CAST(CAST(end_dt AS DATE)AS DATETIME)
ELSE CAST(cal_dt AS DATETIME)
END AS start_dt
,CASE WHEN CAST(start_dt AS DATE) = b.cal_dt THEN CAST(DATEADD(day,1,CAST(start_dt AS DATE))AS DATETIME)
WHEN CAST(end_dt AS DATE) = b.cal_dt THEN end_dt
ELSE CAST(DATEADD(day,1,cal_dt) AS DATETIME)
END AS end_dt
FROM Table1 a
JOIN lkp_Calendar b
ON b.cal_dt BETWEEN CAST(start_dt AS DATE) AND CAST(end_Dt AS DATE)
活动:
<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() );
}
答案 0 :(得分:3)
我今天面临同样的问题,最后我发现我忘了在AndroidManifest.xml文件中添加权限公告。我添加
后就好了<uses-permission android:name="android.permission.INTERNET"/>
AndroidManifest.xml中的
答案 1 :(得分:1)
您可能是此错误的受害者:
Issue 424599: Failed to load resource: net::ERR_CACHE_MISS error when opening DevTools on PHP pages
对于具有Cache-Control
响应标头
答案 2 :(得分:1)
您的代码:
if (Build.VERSION.SDK_INT >= 19) {
_taskOrganizerView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
如果您从未加载&#34; http://www.google.com&#34;,则setCacheMode LOAD_CACHE_ELSE_NETWORK会出错,您可以:
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
//setWebView Gone
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, final String url) {
super.onPageFinished(view, url);
}
答案 3 :(得分:1)
在android清单文件中的应用程序标记之外使用Internet权限。
答案 4 :(得分:0)
在上面的代码中,您似乎正在尝试在<application>
标签中设置权限。
正如处于this answer状态的@zehata一样,应在清单文件的<application>
标记之外授予权限。首先将其放在正确的位置,因为该位置似乎也很重要。
尝试这样的事情:
<manifest package="your.awesome.package"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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"/>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- more content of manifest file -->
</manifest>