您的位置:首页 > 移动开发 > Android开发

Android如何解决异常问题

2016-05-15 11:34 302 查看
一般在报错信息的后面几行,特别和你应用程序有关的类,可以双击点入进行查看
1. Caused by: java.lang.SecurityException:Permission denied (missing INTERNET permission?)
   
解释:安全异常---缺少了INTERNET的权限
2.org.json.JSONException: No value for datas
   
解释:被JSONException捕获的异常:datas这个标签取没有值
3. Caused by: NullPointerException:***
   
解释:空指针异常    
    1)可能1:使用对对象没有开辟空间,使用的对象没有new
    2)可能2:被引用的对象没有开辟空间,被使用的对象没有new
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'
 解释:是这id:btn_normallist的button没有在代码里找到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窗口关了,重新打开
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: