I tried the example shown on Android developers website to show a webpage on a WebView component without success. The emulator shows the following error:
Webpage not available the webpage at http://developer.android.com could not be loaded because: net::ERR_CHACHE_MISS
I could not find any solution so far, even after looking on other threads on the web. I have also tried different links. I do not know if could be helpful in understanding the cause of this error, but the emulator is Nexus 4 API 21 with Android 5.0.1. I am using Android Studio 1.0.
The code is the same of the example:
In MainActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://developer.android.com/");
}
In AndroidManifest:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.INTERNET" />
.....
And in the view I have added the same code of the example
Example is on: http://developer.android.com/guide/webapps/webview.html
JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView .You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.id.webview);
Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.
If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.
Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.
Exactly, It has occured to me once and the solution was to put the following line: <uses-permission android:name="android.permission.INTERNET"/>
before the <application
tag in the manifest.xml file.
Either that line is missing or it's misplaced (eg. at the end of the </manifest>
tag.
In case anyone else encounters this problem and since there isn't an answer here I thought I'd provide one.
For me it turned out to simply be the order the tags were in the manifest file. The user-permission element needs to appear before the application element. I just put it directly under the manifest element at the top and that seemed to do the trick for me.
I had the same error and I fixed with
inside the activity, like this:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<uses-permission android:name="android.permission.INTERNET" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Because I build inside the main activity the webView.... I hope this will help someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With