简体   繁体   中英

Why I am getting an error when I use webview in android?

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

在此处输入图片说明

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 ?

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,

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM