I recently ran into this problem, and in my case, I was able to find out that fixing the secondary error caused this problem.
So, if you have not created a custom class that extends webview, this overrides onCheckIsTextEditor to always return true due to the suggestion in this Android error report ... I would stop reading here.
If you did this, then it seems that this fix has already been implemented by HTC and, for some reason, will cause it to fail to get focus. This problem manifested itself in two places for me, when placing sensory events in the presentation and establishing the visibility of the views. In my project, I installed WebViewClient and waited for the page to finish loading before setting the visibility of the web view to visible. This caused the following stack trace:
java.lang.NullPointerException at android.webkit.WebView.navHandledKey(WebView.java:9353) at android.webkit.WebView.requestFocus(WebView.java:7910) at android.view.View.requestFocus(View.java:3718) at android.view.View.requestFocus(View.java:3696) at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1803) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:474) at android.view.View.setFlags(View.java:4680) at android.view.View.setVisibility(View.java:3163)
By wrapping the setVisibility call in try / catch, I was able to determine if I should override touch events or not. If I caught the event, it would mean that I have to disable the override. This is an example of what I did:
try { webView.setVisibility(View.VISIBLE); } catch (NullPointerException e) { Log.i(TAG, "Error setting webview visibility due to overriding focus. It will be disabled."); webView.setOverrideOnCheckIsTextEditor(false); // Confirm window is visible webView.setVisibility(View.VISIBLE); }
Now my custom webview looks like this, special attention is paid to the last two methods:
public class FocusableWebView extends WebView { private boolean mOverrideCheckIsTextEditor = true; public FocusableWebView(Context context) { super(context); } public FocusableWebView(Context context, AttributeSet attrs) { super(context, attrs); } public FocusableWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onCheckIsTextEditor() { if (mOverrideCheckIsTextEditor) { return true; } else { return super.onCheckIsTextEditor(); } } public void setOverrideOnCheckIsTextEditor(boolean foo) { mOverrideCheckIsTextEditor = foo; } }
Sorry, I canβt explain in more detail why this fixes the problem. All I can assume is that his attitude towards focus and his dynamic shutdown works :)
** Update (12/11/12) **
It was possible to solve both problems presented above. This seemed to be a web browsing focus issue. Now my code looks like
webView.setVisibility(View.VISIBLE); webView.setFocusable(true); webView.requestFocus();
I would advise making sure that you explicitly set the focusable attribute to "true" or call setFocusable (true).