Android如何解決異常問題


通常在報錯信息的後面幾行,特別和你應用程序有關的類,能夠雙擊點入進行查看java

1. Caused by: java.lang.SecurityException:Permission denied (missing INTERNET permission?)android

    解釋:安全異常---缺乏了INTERNET的權限json

2.org.json.JSONException: No value for datas數組

    解釋:JSONException捕獲的異常:datas這個標籤取沒有值安全

3. Caused by: NullPointerException:***app

    解釋:空指針異常    eclipse

    1)可能1:使用對對象沒有開闢空間,使用的對象沒有newide

    2)可能2:被引用的對象沒有開闢空間,被使用的對象沒有newoop

4. Caused by: OOM( out of memory)佈局

    解釋:若是當一次性加載圖片的大小超過4MB的時候,會報這樣的錯誤

5.java.lang.ClassCastException:java.lang.String cannot be cast tocom.qianfeng.gridviewfromnet.MainActivity$MyAdapter$ViewHolder

    解釋:類型轉換錯誤,String不能被轉換成MyAdapter裏的ViewHolder

6.Caused by:android.content.ActivityNotFoundException: Unable to find explicit activityclass{com.qianfeng.day41_gridviewicon/com.qianfeng.day41_gridviewicon.GridViewActivity};have you declared this activity in your AndroidManifest.xml?

   解釋:沒有去清單文件申明指定的activity 

7.java.lang.IllegalStateException:Could not find a method btnClick(View) in the activity classcom.qianfeng.day41_dialoglist.MainActivity for onClick handler on view classandroid.widget.Button with id 'btn_normallist'

 解釋:是這idbtn_normallistbutton沒有在代碼裏找到btnClick(View)

8.android.content.res.Resources$NotFoundException:String resource ID #0x0

 解釋:資源的地址沒有被找到

 可能:設置的參數應該是0x....的地址,但實際卻被賦值了


9. java.lang.IndexOutOfBoundsException:Invalid index 3, size is 2

解釋:數組下標越界

10.android.view.WindowManager$BadTokenException:Unable to add window -- token null is not valid; is your activity running?

解釋:你的Activity沒有徹底的運行起來,卻在window窗口去顯示popUpMenu



------------------------------------------------------------------------------------

關於Fragment的錯誤

11.java.lang.RuntimeException: Unable tostart activityComponentInfo{com.qianfeng.day43_fragmentlifecycle/com.qianfeng.day43_fragmentlifecycle.MainActivity}:android.view.InflateException: Binary XML file line #11: Error inflating classfragment

解釋:視圖佈局填充錯誤:11行的標籤不能轉換視圖

解決方法: atandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)

              讓你在onCreateView方法裏添加本身的View


12.Permission Denial: opening providercom.android.providers.contacts.CallLogProvider from ProcessRecord{b14062a02003:com.qianfeng.day46_calllog/u0a64} (pid=2003, uid=10064) requiresandroid.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG

解釋:申請權限:android.permission.READ_CALL_LOG|android.permission.WRITE_CALL_LOG


13.Unable to start activityComponentInfo{com.qianfeng.day46_calllog/com.qianfeng.day46_calllog.MainActivity}:java.lang.IllegalArgumentException: column '_id' does not exist

解釋:指定的_id這一列沒有被找到

14.ClassLoader Exception:

解釋:類加載錯誤(清單文件註冊的時候,類的名字寫錯 , alt+/找到指定的類)





15.android.view.ViewRootImpl$CalledFromWrongThreadException:Only the original thread that created a view hierarchy can touch its views.

解釋:只有建立該view的線程能夠更改他的視圖View,其餘的線程不能夠



16.java.lang.RuntimeException: Can'tcreate handler inside thread that has not called Looper.prepare()

解釋:若是要在本身定義的線程裏運行消息隊列正常,必須本身開啓Looper.prepare

         本身定義的線程Looper要本身控制,系統只處理main線程的Looper



17.java.lang.IllegalStateException: Youneed to use a Theme.AppCompat theme (or descendant) with this activity. 

解釋:ActionBar v7對樣式有要求:appcompat項目下的樣式


Log不輸出

用eclipse進行android開發中常常遇到logcat無任何信息輸出,這給咱們調試程序帶來很大的不便。解決辦法:window-->show view-->選擇android下的devices,打開devices,點擊右邊的截屏圖片。等到出現截圖的時候,logcat就出來信息了!

在補充一下,若是以上方法試過以後logcat尚未任何信息,則把logcat窗口關了,從新打開