【发布时间】:2015-07-09 12:24:54
【问题描述】:
我正在尝试创建一个将 url 加载到 webview 中的简单应用程序。但是,我不断收到net::ERR_CACHE_MISS。我已经添加了互联网的相关权限,这似乎是导致错误的最常见原因。
这是我的代码:
public class MainActivity extends AppCompatActivity {
private static String TAG = "Main";
@Override
protected void onCreate(Bundle savedInstanceState) {
// getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
WebView webview = (WebView)findViewById(R.id.web_view);
webview.setWebViewClient(new myWebviewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://www.foodport.co.in");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class myWebviewClient extends WebViewClient {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.i(TAG, "onReceivedError "+ errorCode);
}
}
我已将<uses-permission android:name="ANDROID.PERMISSION.INTERNET"/> 添加到清单文件中。
有什么帮助吗?我唯一的线索是在同一部手机上有另一个应用程序使用相同的包名称,但这也是所有权限。 我正在检查运行 Android 4.4 的手机,我检查了this post,但我认为这不是问题。
【问题讨论】:
-
“我不断得到 net::ERR_CACHE_MISS”——你从哪里得到这个?在 LogCat 中?在
onReceivedError()?其他地方? -
是的,在
onRecievedError(),也在网络视图本身