2013-01-07 44 views
0

我正試圖在我的android應用程序中實現搜索。我按照教程建議的步驟進行搜索,以便進行搜索。我用按鈕實現了搜索。只要我按下按鈕,並不總是,但有時我的Logcat顯示此錯誤和應用程序stops.This不會總是發生,但有時,我不知道爲什麼發生這種情況,如果這是一個問題比當我點擊搜索按鈕時總會出現錯誤。使用Android Search搜索執行搜索期間java.lang.illegalStateException

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 
    } 

} 
+3

真正的問題是'由於:java.lang.OutOfMemoryError'你在內存中有太多的位圖 – njzk2

回答

0

此事故發生由於Out of Memory Exception在日誌中給出的片段。搜索圖標未正確加載。有效使用Bitmaps請看this

+0

你能詳細說明drawables和bitmap之間的區別嗎?我在我的應用程序中使用drawables並且混淆了位圖.. – aneela