Monday, May 13, 2013

[android help] HelloWebViewClient cannot be resolved to a type

android - HelloWebViewClient cannot be resolved to a type - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















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;

}
};
}
});
}}

























What if you put that class outside?



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());
}
});
}

private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}

}






















Change



mWebView = (WebView) findViewById(R.id.webview);


to



mWebView = (WebView) test.this.findViewById(R.id.webview);


Also, in Java class names should start with a capital letter.






















The problem is that you declare your class AFTER you use it. Move line mWebView.setWebViewClient(new HelloWebViewClient()); AFTER class declaration.























default







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...