In my Android app, when I create a new emulator and try to write in webview for the first time, it’s not active. I can’t write in textfield and then the app crashes. If I reload the app all works OK.
Code:
String url = "http://api.vkontakte.ru/oauth/authorize?client_id=2731649&scope=wall,notify,docs&" +
"redirect_uri=http://api.vkontakte.ru/blank.html&display=wap&response_type=token";
WebViewClass wvClforVK = new WebViewClass();
In oncreate:
webview= (WebView) findViewById(R.id.vkWebView);
webview.setWebViewClient(wvClforVK);
On buttonclick:
webview.loadUrl(url);
in wvClforVK
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
You must set the content view BEFORE attempting to use any components such as your R.id.vkWebView. If you use
findViewById(...)before setting content view, it will return null.To set the content view call…
…assuming your layout file is called
main.xmlbut you don’t put the .xml part on it when using R.layout. Usually you will set the content view as early in an activity’sonCreate(...)method as possible. This is often done immediately after the call tosuper.onCreate(...);