Reputation: 71
this is a re-post of a question i asked last week, got 2 answers that didn't work.
i followed a guide on http://developer.android.com/resources/tutorials/views/hello-webview.html and then created my own EditText field and a button. the code should explain it all, my problem is i keep getting a "HelloWebViewClient cannot be resolved to a type" Error, any suggestions? thanks in advance!
package com.text.text;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alt);
final EditText edittext = (EditText) findViewById(R.id.edittext);
final Button button = (Button) findViewById(R.id.okay);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Editable text = edittext.getText();
String Tekst = text.toString();
setContentView(R.layout.main);
WebView mWebView;
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(Tekst);
mWebView.setWebViewClient(new HelloWebViewClient());
class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
}
});
}}
Upvotes: 3
Views: 11722
Reputation: 1792
I had this problem as well and the issue turned out to be the following missing packages hadn't been imported (you already have one in your source:
import android.webkit.WebView;
import android.webkit.WebViewClient;
This is in the example posted by CommonsWare, but is not included in the tutorial for some reason.
Upvotes: 10
Reputation: 1006944
Move HelloWebViewClient
from its current location to outside of onCreate()
(but inside your test
class). Here is a sample project demonstrating this.
Upvotes: 1