Saliko
Saliko

Reputation: 164

WebView not showing on android emulator

I need the webview to show the google URL but when I run the app I get nothing.Also nothing is printed in the logcat.I also tried to load the html data but still didn't work. Here is my code:

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView webView = findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http//www.google.com");
    //webView.loadData("<html><body><h1>Hello World</h1><p>This is my website</p></body></html>","text/html", "UTF-8");
}
}

Upvotes: 1

Views: 1431

Answers (1)

edwin
edwin

Reputation: 65

Give android permission to access the internet in the AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET"></uses-permission>

Upvotes: 1

Related Questions