Question

I am new to android and have written the code for web view to display the url given onto that.

The error is as below

enter image description here

Why I am getting this error I have used the correct logic in my problems and i haven't got any errors

So kindly please let me know how to rectify it ?

Th code used is :

package com.coded.sandeep;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView webView = (WebView) findViewById(R.id.webview);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    webView.loadUrl("http://www.google.com");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}}

can anyone debug or it is an internet connection error ?

Was it helpful?

Solution

There is a androidmanifest.xml file in your project. Just open that file and write following line init.

<uses-permission android:name="android.permission.INTERNET" />

You need to write this line after <uses-sdk tag and before <application> tag.

See the image below,

enter image description here

OTHER TIPS

add below permission into your manifest.xml file

 <uses-permission android:name="android.permission.INTERNET" />

and also make sure your Internet Data Connection Turn ON

Add the INTERNET permission to your manifest file.

You have to add this line:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
outside the application tag in your AndroidManifest.xml
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top