2012年12月11日 星期二

[Resolved] Android: WebView Web Page not available

Today I'm trying to create a WebView in Android, it shows a Web page not available after running the app in the emulator.




       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              WebView wv = (WebView) findViewById(R.id.webView1);             
              wv.loadUrl("https://www.google.com");
             
                }

Solution 

1. Make sure the permission is granted
<uses-permission android:name="android.permission.INTERNET"></uses-permission>


2. Make sure the following bold content in your code
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              WebView wv = (WebView) findViewById(R.id.webView1);
              wv.setWebViewClient(new WebViewClient(){});
             
              wv.loadUrl("https://www.google.com");
             
                }

沒有留言:

張貼留言