23.在使用AndroidHttpClient时有如下错误: 01-16 22:18:39.222: E/AndroidHttpClient(26745): java.lang.IllegalStateException: AndroidHttpClient created and never closed 这个主要是因为没有调用AndroidHttpClient的close()方法。它的close()方法如下: ?
1 /**
2 * Release resources associated with this client. You must call this, 3 * or significant resources (sockets and memory) may be leaked. 4 */
5 public void close() {
6 if (mLeakedException != null) {
7 getConnectionManager().shutdown(); 8 mLeakedException = null; 9 } 10 }
在我们的使用中在finally语句块中调用其close方法即可。 ?
1 finally {
2 if(httpClient != null) { 3 httpClient.close(); 4 } 5 }
最后更新:2012-11-12
23,在使用一个FrameLayout作为容器时,将一个Frament实例动态添加进布局时,出现如下错误提示:
The specified child already has a parent. You must call removeView() on the child's parent first. 解决办法就是: 在 ?
1 @Override
2 public View onCreateView(LayoutInflater inflater, ViewGroup container, 3 Bundle savedInstanceState) {
4 Log.i(DIALOG_FRAGMENT, \"====(3)onCreateView========>\"); 5 View view = inflater.inflate(R.layout.auth, container, false); 6 initViews(view); 7 return view; 8 }
中,使用,注意带参数false
View view = inflater.inflate(R.layout.auth, container, false); 22.android:filterTouchesWhenObscured
view所在窗口被其它可见窗口遮住时,是否过滤触摸事件。
结果因为有些应用会在界面的上面加一层,导致软件不可滑动。所以。
最后更新 2012-04-28
21.接下面的错误: ? 1 2 3 4 5 6 7
05-10 16:16:23.830: W/dalvikvm(15086): threadid=1: thread exiting with uncaught exception (g8
05-10 16:16:23.860: E/AndroidRuntime(15086): FATAL EXCEPTION: main 9
05-10 16:16:23.860: E/AndroidRuntime(15086): java.lang.IllegalStateException: Activity has bee1
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.FragmentManager0
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.BackStackRecord.c1
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.support.v4.app.BackStackRecord.c1
05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.activity.BaseFragmentAct1
05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.activity.BaseFragmentAct2
05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActiv1
05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActiv3
05-10 16:16:23.860: E/AndroidRuntime(15086): at cn.ditouch.client.guilin.DiTouchClientActiv1
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask.finish(AsyncTask.jav4
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask.access$600(AsyncTa1
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.AsyncTask$InternalHandler.han5
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.Handler.dispatchMessage(Hand1
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.os.Looper.loop(Looper.java:137) 6
05-10 16:16:23.860: E/AndroidRuntime(15086): at android.app.ActivityThread.main(ActivityT1
05-10 16:16:23.860: E/AndroidRuntime(15086): at java.lang.reflect.Method.invokeNative(Nati7
05-10 16:16:23.860: E/AndroidRuntime(15086): at java.lang.reflect.Method.invoke(Method.jav1
05-10 16:16:23.860: E/AndroidRuntime(15086): at com.android.internal.os.ZygoteInit$Metho8
05-10 16:16:23.860: E/AndroidRuntime(15086): at com.android.internal.os.ZygoteInit.main(Z1
05-10 16:16:23.860: E/AndroidRuntime(15086): at dalvik.system.NativeStart.main(Native Met9 20 21 22
在此有说是因为FragmentManager自己是在onCreate中初始化的所以要把fragment的操作放到后面去:
http://stackoverflow.com/questions/6938368/why-do-i-get-illegalstateexceptio
ns-every-time-i-start-an-activity-that-uses-sup
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如下: ? 1 05-10 15:47:06.470: W/dalvikvm(12744): threadid=1: thread exiting with uncaught exception (gr2 05-10 15:47:09.850: E/AndroidRuntime(12744): FATAL EXCEPTION: main 3 05-10 15:47:09.850: E/AndroidRuntime(12744): java.lang.IllegalStateException: Can not perform 4 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.FragmentManagerI5 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.FragmentManagerI6 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.BackStackRecord.co7 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.BackStackRecord.co8 05-10 15:47:09.850: E/AndroidRuntime(12744): at android.support.v4.app.DialogFragment.sh在此处有人也一个有点类似问题:
http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-h
我看到上面有提到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时出错: 参考:http://stackoverflow.com/questions/10133078/assistance-please-setting-up-android-support-package-v7-for-eclipse-gridlayou
其中有两个重要的特点: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了.因为如果先设置了这个会与后面添加产生冲突..
14.android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 原来及解决办法:
导致报这个错是在于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中,使用了如下代码. ?
1 return new AlertDialog.Builder(this) 2 .setTitle(\"提醒!\")
3 .setMessage(args.getString(\"MESSAGE\")) 4 .setCancelable(false)
但是,实际使用我发现,如果我是在Activity中托管使用这个的话,在整个Acitivty生命周期中只创建一次,所以,args.getString()就只能得到第一次得到内容. 解决办法是使用onPrepareDialog(),现在知道为什么要这样子设计了. ?
1 @Override
2 protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { 3 AlertDialog aDialog = (AlertDialog) dialog; 4 switch (id) {
5 case DIALOG_FIRE_ALL_ORDER:
6 aDialog.setMessage(args.getCharSequence(\"MESSAGE\")); 7 break;
8 case DIALOG_DELETE_ORDER_NON_FIRED:
9 aDialog.setMessage(args.getString(\"DISH_NAME\")); 10 default: 11 break; 12 } 13 }
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()方法没有报这个错了. Thanks to :http://stackoverflow.com/questions/442/android-error-close-was-never-explicitly-called-on-database
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过去 : ?
1 ToastUtils.showLong(this, \"正在加载楼层数据...\"); 2 new Thread(new Runnable() { 3 @Override
4 public void run() {
5 for (String floorId : FLOOR_NUMS) {
6 final List