0

我正在尝试在我的 android 应用程序中实现搜索。我已按照教程建议的步骤使搜索成为可能。我已经使用按钮实现了搜索。当我按下按钮时,并非总是如此,但有时我的 Logcat 会显示此错误并且应用程序会停止。这并不总是发生,但有时,我不知道为什么会发生这种情况,就好像这是一个问题而不是当我单击搜索按钮时,应该始终显示错误。

01-07 13:32:54.759: E/AndroidRuntime(11826): FATAL EXCEPTION: main
01-07 13:32:54.759: E/AndroidRuntime(11826): java.lang.IllegalStateException: Could not execute method of the activity
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.view.View$1.onClick(View.java:3050)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.view.View.performClick(View.java:3517)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.view.View$PerformClick.run(View.java:14155)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.os.Handler.handleCallback(Handler.java:605)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.os.Looper.loop(Looper.java:137)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.ActivityThread.main(ActivityThread.java:4508)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at java.lang.reflect.Method.invokeNative(Native Method)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at java.lang.reflect.Method.invoke(Method.java:511)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at dalvik.system.NativeStart.main(Native Method)
01-07 13:32:54.759: E/AndroidRuntime(11826): Caused by: java.lang.reflect.InvocationTargetException
01-07 13:32:54.759: E/AndroidRuntime(11826):    at java.lang.reflect.Method.invokeNative(Native Method)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at java.lang.reflect.Method.invoke(Method.java:511)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.view.View$1.onClick(View.java:3045)
01-07 13:32:54.759: E/AndroidRuntime(11826):    ... 11 more
01-07 13:32:54.759: E/AndroidRuntime(11826): Caused by: java.lang.OutOfMemoryError
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.Bitmap.nativeCreate(Native Method)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:543)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:518)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:370)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.content.res.Resources.loadDrawable(Resources.java:1935)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.content.res.Resources.getDrawable(Resources.java:664)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.ApplicationPackageManager.getDrawable(ApplicationPackageManager.java:580)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:140)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.ApplicationPackageManager.getApplicationIcon(ApplicationPackageManager.java:637)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchDialog.updateSearchAppIcon(SearchDialog.java:438)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchDialog.updateUI(SearchDialog.java:391)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchDialog.show(SearchDialog.java:278)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchDialog.doShow(SearchDialog.java:230)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchDialog.show(SearchDialog.java:212)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.SearchManager.startSearch(SearchManager.java:526)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at  android.app.SearchManager.startSearch(SearchManager.java:503)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.Activity.startSearch(Activity.java:3055)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at android.app.Activity.onSearchRequested(Activity.java:3018)
01-07 13:32:54.759: E/AndroidRuntime(11826):    at com.vahzay.android.smstrove.ListMessages.onsearchClick(ListMessages.java:150)
01-07 13:32:54.759: E/AndroidRuntime(11826):    ... 14 more

这是导致此错误的代码段

    public void onsearchClick(View v) {

    if (v.getId() == R.id.searcher) {
        Log.i("search has been clicked", "show");

        // this method is used to call the search activity from the
        // listmessages activity no intent is used as its need a special
        // functionality
        onSearchRequested(); // line no 150
    }

}
4

1 回答 1

0

发生此崩溃的原因Out of Memory Exception是您的日志中给出了。搜索图标未正确加载。要有效地使用位图,请查看

于 2013-01-07T08:48:14.777 回答