最後更新:2013-01-16html
23.在使用AndroidHttpClient時有以下錯誤:java
01-16 22:18:39.222: E/AndroidHttpClient(26745): java.lang.IllegalStateException: AndroidHttpClient created and never closed
這個主要是由於沒有調用AndroidHttpClient的close()方法。它的close()方法以下:android
/** * Release resources associated with this client. You must call this, * or significant resources (sockets and memory) may be leaked. */ public void close() { if (mLeakedException != null) { getConnectionManager().shutdown(); mLeakedException = null; } }
在咱們的使用中在finally語句塊中調用其close方法便可。web
finally { if(httpClient != null) { httpClient.close(); } }
最後更新:2012-11-12sql
23,在使用一個FrameLayout做爲容器時,將一個Frament實例動態添加進佈局時,出現以下錯誤提示:shell
The specified child already has a parent. You must call removeView() on the child's parent first.
解決辦法就是: windows
在 網絡
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i(DIALOG_FRAGMENT, "====(3)onCreateView========>"); View view = inflater.inflate(R.layout.auth, container, false); initViews(view); return view; }
中,使用,注意帶參數falseapp
View view = inflater.inflate(R.layout.auth, container, false);
eclipse
22.android:filterTouchesWhenObscured
view所在窗口被其它可見窗口遮住時,是否過濾觸摸事件。
結果由於有些應用會在界面的上面加一層,致使軟件不可滑動。因此。
最後更新 2012-04-28
21.接下面的錯誤:
05-10 16:16:23.830: W/dalvikvm(15086): threadid=1: thread exiting with uncaught exception (group=0x40a4b1f8) 05-10 16:16:23.860: E/AndroidRuntime(15086): FATAL EXCEPTION: main 05-10 16:16:23.860: E/AndroidRuntime(15086): java.lang.IllegalStateException: Activity has been destroyed 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1314) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:529) 05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.activity.BaseFragmentActivity.removeFragmentDialog(BaseFragmentActivity.java:129) 05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.activity.BaseFragmentActivity.removeFragmentDialog(BaseFragmentActivity.java:114) 05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActivity.access$1(DiTouchClientActivity.java:1) 05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActivity$ConnectServerTask.onPostExecute(DiTouchClientActivity.java:299) 05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActivity$ConnectServerTask.onPostExecute(DiTouchClientActivity.java:1) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask.finish(AsyncTask.java:602) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask.access$600(AsyncTask.java:156) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.Handler.dispatchMessage(Handler.java:99) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.Looper.loop(Looper.java:137) 05-10 16:16:23.860: E/AndroidRuntime(15086): at android.app.ActivityThread.main(ActivityThread.java:4424) 05-10 16:16:23.860: E/AndroidRuntime(15086): at java.lang.reflect.Method.invokeNative(Native Method) 05-10 16:16:23.860: E/AndroidRuntime(15086): at java.lang.reflect.Method.invoke(Method.java:511) 05-10 16:16:23.860: E/AndroidRuntime(15086): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 05-10 16:16:23.860: E/AndroidRuntime(15086): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-10 16:16:23.860: E/AndroidRuntime(15086): at dalvik.system.NativeStart.main(Native Method)
在此有說是由於FragmentManager本身是在onCreate中初始化的因此要把fragment的操做放到後面去:
20. 在debug帶有android.support.v4的包時,結果出現下面的錯誤:
05-10 15:47:09.850: E/AndroidRuntime(12744): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
比較完整的stack以下:
05-10 15:47:06.470: W/dalvikvm(12744): threadid=1: thread exiting with uncaught exception (group=0x40a4b1f8) 05-10 15:47:09.850: E/AndroidRuntime(12744): FATAL EXCEPTION: main 05-10 15:47:09.850: E/AndroidRuntime(12744): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1299) 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1310) 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541) 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525) 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.DialogFragment.show(DialogFragment.java:123)
在此處有人也一個有點相似問題:
我看到上面有提到onSaveInstanceState(),因而就重寫了下這個.像上面說的不能調用super.我調用了,並且竟然就tmd沒有錯誤提示了..
19.05-10 16:08:43.190: E/AndroidRuntime(14243): java.lang.IllegalStateException: addToBackStack() called after commit()
18.在使用android.support.v7.widget.GridLayout時出錯:
其中有兩個重要的特色:1.要將android-support-v7做爲一個庫引用項目.
而後使用全名.而後,仍是要將android-support-v7做爲一個庫項目,來處理,命名空間等待.
17. android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
這個我本身的是在一個網絡出現異常,因此沒有按順序執行close(),解決辦法是添加finally語句並執行close()語句.
(2012-04-23)
16.04-23 14:50:08.344: E/AndroidRuntime(28034): Caused by: java.lang.IllegalStateException: Fragment cn.ditouch.client.activity.EditMenuxFragment did not create a view.
在使用Fragment中出現上面的錯誤,我是照着Google Android的文檔來作的.
錯誤的緣由是我將FrameLayout當作了fragment想固然了...
15. android.util.AndroidRuntimeException: requestFeature() must be called before adding content
在爲AlertDialog中使用自定義佈局時,在Builder中調用 了create()後不當心在使用了setContentView()
事實上也不該該在使用setConentView了.由於若是先設置了這個會與後面添加產生衝突..
原來及解決辦法:
致使報這個錯是在於new AlertDialog.Builder(mcontext),雖然這裏的參數是AlertDialog.Builder(Context context)但咱們不能使用getApplicationContext()得到的Context,而必須使用Activity,由於只有一個Activity才能添加一個窗體。
Thanks to :http://blog.csdn.net/Vincent_czz/article/details/5777725
13. 在使用AlertDialog中,使用了以下代碼.
return new AlertDialog.Builder(this) .setTitle("提醒!") .setMessage(args.getString("MESSAGE")) .setCancelable(false)
可是,實際使用我發現,若是我是在Activity中託管使用這個的話,在整個Acitivty生命週期中只建立一次,因此,args.getString()就只能獲得第一次獲得內容.
解決辦法是使用onPrepareDialog(),如今知道爲何要這樣子設計了.
@Override protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { AlertDialog aDialog = (AlertDialog) dialog; switch (id) { case DIALOG_FIRE_ALL_ORDER: aDialog.setMessage(args.getCharSequence("MESSAGE")); break; case DIALOG_DELETE_ORDER_NON_FIRED: aDialog.setMessage(args.getString("DISH_NAME")); default: break; } }
12.在ListView的適配器中出現:java.lang.IndexOutOfBoundsException: Invalid index 32, size is 23
緣由是我在getView()中使用了.
mCheckBoxList.add(position, holder.check);
解決辦法是,使用:mCheckBoxList.add(mCheckBoxList.size(), holder.check);
11.NetworkOnMainThreadException
當我把targetSdkVersion設置爲11時,我原來在UI線程執行網絡操做的代碼
就會出現上面的異常,解決辦法是使用AsyncTask來網絡操做.或者使用其餘的網絡庫如Volley,
10. close() was never explicitly called on database
04-12 17:19:34.020: E/SQLiteDatabase(2743): close() was never explicitly called on database '/data/data/xx.db'
這個在我使用完SQLiteOpenHelper的子類對象以後調用close()方法沒有報這個錯了.
9.在使用SQLiteOpenHelper時出現這樣一個錯誤:Can't upgrade read-only database from version 0 to 1
04-12 16:59:11.230: E/AndroidRuntime(2119): android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/databases/xx.db
從輸出的log中我發現如今這個錯誤的時候,同時前面會有一個sql語法錯誤.
解決辦法是根據提示,仔細檢查sql語句看是否有錯誤.
8.在UI線程中開了一個線程來初始化一個ViewFlipper.
致使下面的錯誤 :
04-10 14:08:36.356: E/AndroidRuntime(26716): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
解決辦法使用post方法將操做post過去 :
ToastUtils.showLong(this, "正在加載樓層數據..."); new Thread(new Runnable() { @Override public void run() { for (String floorId : FLOOR_NUMS) { final List<Table> tables = TableDao.findByFloorId(floorId); mFloorFlipper.post(new Runnable() { @Override public void run() { buildFloorView(tables); } }); } } }).start();
7.在使用LayoutInflater.inflate()時常常被第地個參數給搞定了.我是在適配器上使用的:
public View getView(int position, View convertView, ViewGroup parent) { if (convertView != null)return convertView; View view = mInflater.inflate(R.layout.menu_item, parent);
錯誤信息以下:
04-02 02:49:06.322: E/AndroidRuntime(494): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
應該改爲下面這樣 :mInflater.inflate(R.layout.menu_item,parent,false);由於咱們須要使用parent來幫助構造LayoutParams,但不是要添加進parent
6.在使用SharedPreferences的時候,使用了getPreferences().可是這個是隻供本Acitivity使用的.
若是在本應用的其它activity中共享這些設置,就要使用getSharedPreferences();
5.第四個錯誤說到,要在每個ListView中的項中實現,手勢滑動判斷,刪除功能.可是若是沒有設置背景圖片或者背景色的時候,當手滑動區域超過一個ListView的項時,就會出現ListView項背景反色,非常讓人討厭,一開始我覺得是由於,ListView項,得到了焦點的緣由,就嘗試在項中的GestureOverlayView中及在其中的TextView的onTouch方法中若是MotionEvent的action爲down的話,就返回true,這個系統就不會處理高亮反色了,可是其實不是這樣的,究竟是怎麼樣的呢?
目前還不清楚,個人解決辦法是在GestureOverlayView中設置一張背景圖片.就OK了.就算這個ListView中各個項高亮反色了.
也不會影響.
錯誤設置代碼以下,處理高亮仍是不要這樣用了-在這樣的場景下:
private static class IgnoreTouchListener implements View.OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { Log.i(TAG, "Ignore touch" + v.getClass() + "," + event.getAction()); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: return true; default: break; } return false; } }
4. 如今的一個須要是要在一個ListView的項中滑動時,就表示刪除其中一個項.
開始用GestureDetector可是,弄了好久仍是沒有反應.因此做罷,關鍵在一個項中,我喜歡滑動的時候可以有像用筆畫線同樣的效果.
ListView中的項對應佈局文件以下 :(名爲:orderlist_item.xml)
<?xml version="1.0" encoding="utf-8"?> <android.gesture.GestureOverlayView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gestures" android:layout_width="fill_parent" android:layout_height="fill_parent" android:eventsInterceptionEnabled="true" android:background="@drawable/bg_current_order_item" android:orientation="vertical"> <TextView android:id="@+id/order_list_item_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:text="TextView01" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerHorizontal="false" > </TextView> </android.gesture.GestureOverlayView>
開始嘗試:這樣:
GestureOverlayView gestures = (GestureOverlayView)findViewById(R.id.gestures); gestures.addOnGesturePerformedListener(this);
可是這樣會報空指針錯誤,就是取不到gestures.可是我幫android的示例項目也是這樣的.android資源中文章:
docs/resources/articles/gestures.
後來我想了一下,在android中的示例項目 中,這是一惟一的一個文件,可是在個人使用場景中這樣的一個文件在ListView中重複使用了,想起來這樣的一個ID也會在上面存在多個.因而用R.id.gestures是找不到了,就算用R.layout.orderlist_item也找不到.
因而我就在本身實現的BaseAdapter中的View來處理這樣的邏輯了:
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; if (convertView == null) { view = mInflater.inflate(R.layout.orderlist_item, null); TextView textView = (TextView) view .findViewById(R.id.order_list_item_text); Map<String, Object> map = (Map<String, Object>) mData .get(position); String itemText = (String) map.get(ITEM_TEXT); textView.setText(itemText); view.setTag(mData.get(position)); GestureOverlayView gestures = (GestureOverlayView) view; gestures.addOnGesturePerformedListener(ClientStationActivity.this); } return view; }
其中處理在主Activity中實現的OnGesturePerforedListener接口,其中處理方法 以下 :
@Override public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = mLibrary.recognize(gesture); if (predictions.size() < 1) return; if (predictions.get(0).score < 0.27) return; String action = predictions.get(0).name; Log.i(TAG, "action:" + action + "," + predictions.get(0).score); Map<String, Object> map = (Map<String, Object>) overlay.getTag(); String itemText = (String) map.get(ITEM_TEXT); // TODO 完成刪除 }
上面的代碼有一個要注意的地方就是.經過實際的手勢來判斷看你認爲的一個比較正確的手勢的score得分是多少.
3.
不能在android項目中運行Java程序.
有時候想運行測試一下一個簡單的Java方法,可是呢今天發現了這樣一個問題:
而後我就想通了.
報告錯誤以下 :
# # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (classFileParser.cpp:3494), pid=2260, tid=2492 # Error: ShouldNotReachHere() # # JRE version: 6.0_31-b05 # Java VM: Java HotSpot(TM) Client VM (20.6-b01 mixed mode windows-x86 ) # An error report file with more information is saved as: # E:\workspace\demo\hs_err_pid2260.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp #
1.
03-17 04:14:51.044: E/AndroidRuntime(390): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
說的是在RelativeLayout循環引用了吧。我相對你,你又相對我。哈哈。
2.
03-17 08:27:04.605: E/AndroidRuntime(610): java.lang.RuntimeException: Unable to start activity ComponentInfo{}: android.content.res.Resources$NotFoundException: String resource ID #0x7f060004
事實上我看到我項目的R文件上有這麼一句:
public static final int new_table=0x7f060004;
而我引用資源的代碼以下:
private static final int[] LABELS = new int[] { R.string.new_table, R.string.find_bill, R.string.change_waiter, R.string.reconnect_server, R.string.exit_system }; getString(LABELS[i])
上網暫時沒有查找到什麼有用的,由於別人出現這個錯誤是由於在setText()的時候直接用了int型的值。
我呢?哎。
而後我在回學校路上一直在想,而後我想,忽然,我想起了android查找資源的的解析方法.
由於我開始開發時只提供了values-zh的字符串值,而沒有提供values下的默認字符串值.
由於模擬器默認的語言環境是英文的,因此就不會去查找values-zh下的字符串資源.
因此纔會致使上面的錯誤.
而後只要在values中添加對應的字符串資源就OK了.
但願個人這個錯誤,能給你們在遇到這個錯誤時,提供一些解決問題的啓示.
在android的參考文檔 guide/topics/resources/providing-resources.html 能夠了解更多.