I have tested the last code by @Zhuinden in page how to search text in webview on my Samsung S3 with android 4.1.2 and works fine in spite of using findAll() which is deprecated, but I've got force close error on android 2.2 emulator. This is the LogCat Error:
08-29 00:34:23.454: E/AndroidRuntime(450): FATAL EXCEPTION: main
08-29 00:34:23.454: E/AndroidRuntime(450): java.lang.NoSuchMethodError: com.tafasir.tafseerenoor.SearchDemoActivity.getActionBar
08-29 00:34:23.454: E/AndroidRuntime(450): at com.tafasir.tafseerenoor.SearchDemoActivity.onCreate(SearchDemoActivity.java:34)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.os.Looper.loop(Looper.java:123)
08-29 00:34:23.454: E/AndroidRuntime(450): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-29 00:34:23.454: E/AndroidRuntime(450): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 00:34:23.454: E/AndroidRuntime(450): at java.lang.reflect.Method.invoke(Method.java:521)
08-29 00:34:23.454: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-29 00:34:23.454: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-29 00:34:23.454: E/AndroidRuntime(450): at dalvik.system.NativeStart.main(Native Method)
How can we solve the problem in order to run it on old android systems without error?
Edited after doing "gedr" help
Thank you for your help "gedr". I have added "gedr" suggested code and also imported android.support.v7.app.ActionBar. My class extends ActionBarActivity and I get error with mActionBar = getActionBar();
Type mismatch: cannot convert from android.app.ActionBar to android.support.v7.app.ActionBar
also it doesn't let me to change extends from ActionBarActivity to SupportActionBarActivity, because I get a lot of errors with different codes. This is some parts of my code which I used it:
public class SearchDemoActivity extends ActionBarActivity implements View.OnClickListener
{
WebView mWebView;
private RelativeLayout container;
private Button nextButton, closeButton;
private EditText findBox;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
// Begin Help code to remove android 2.2 error
ActionBar mActionBar = null;
if (android.os.Build.VERSION.SDK_INT >= 8) {
mActionBar = getActionBar(); //Error Line: Type mismatch: cannot convert from android.app.ActionBar to android.support.v7.app.ActionBar
} else {
mActionBar = getSupportActionBar();
}
// END Help code to remove android 2.2 error
mActionBar.setTitle(R.string.information_display);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("file:///android_res/raw/index.htm");
How can I solve it now?