Reputation: 13
Good day,
I have no experience with Android or Java but I was following a tutorial when I encountered this Error "Cannot Resolve Symbol WebView", "Cannot Resolve Method setWebViewClient" and "Cannot Resolve Method loadUrl".
Can someone perhaps explain what is wrong and how to fix it based on the following code:
package com.example.riegie.test;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview); // Errors
webView.setWebViewClient(new WebViewClient()); // Errors
webView.loadUrl("http://www.google.com"); // Errors
}
}
Upvotes: 0
Views: 738
Reputation: 58934
You should learn to basics bro.
You can not use any class without importing it. Try below code.
package com.example.riegie.test;
import android.webkit.WebView; // you missed this line
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.google.com");
}
}
If you are new to Android you should learn some basic keymap.
ctrl + space = auto complete
alt + enter = see suggestion (useful for compile time error also, which you faced)
Fore more One good article on keymap
Upvotes: 1