I'm trying to create a simple App that loads a url into a webview. However, I keep getting net::ERR_CACHE_MISS
. I've added the relevant permission for the internet which seemed the most common cause for the error.
Here is my code:
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);
}
}
I've added <uses-permission android:name="ANDROID.PERMISSION.INTERNET"/>
to the manifest file.
Any help? The only clue I have is that a had another app using the same package name on the same phone, but that also that all the permissions. I'm checking on a phone which runs Android 4.4, I checked this post but I don't think this is the problem.