Android常见异常记录

来源:互联网 发布:java并查集 编辑:程序博客网 时间:2024/05/18 03:52
1.UNIQUE constraint failed:主键不唯一(greenDao中实体类的id属性必须为Long,而不能为long)

2. 在非主线程中直接new Handler() 会报如下的错误:
E/AndroidRuntime( 6173): Uncaught handler: thread Thread-8 exiting due to uncaught exception
E/AndroidRuntime( 6173): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
解决:在子线程中Looper.prepare();

3.android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41910ab0 is not valid; is your activity running?
原因:错误常在PopupWindow.showAtLocation中出现; popwindow必须依附于某一个view,而在oncreate中view还没有加载完毕或者不存在,必须要等activity的生命周期函数全部执行完毕,你需要依附的view加载好后才可以执行popwindow。

4.打包apk出现 is not translated in "zh-rCN" (Chinese: China)的错误
解决:在window的preferences配置下,打开Android --> Lint Error Checking,turn off 'Run full error check when exporting app'

5.Error: File path too long on Windows, keep below 240 characters
原因:目录名太长
解决:修改工程名或缩短路径

6.java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
原因:activity继承的父类与该activity应用的主题冲突
解决:直接继承Activity或者修改主题类型

7.Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
解决:
①.查看是否有重复导入的jar包
②.修改builde.gradle buildToolsVersion "23.0.2" 改为 最新版
③.builder.gradle 下添加 defaultConfig {
        .....       
        multiDexEnabled true
        .....
    }


    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
另外如果使用了最新的build tools,compilesdk也要使用最新的,依赖的support也使用最新的,三者要保持一致
compile'com.android.support:appcompat-v7:23.+'
testCompile'junit:junit:4.12'
compile'com.android.support:recyclerview-v7:23.+'

8.java.lang.UnsatisfiedLinkError:Native method not found
将一个包含了so库的项目里面的代码和相应的so库复制到要使用的项目,运行后出现上述错误,
原因:包名不一致导致的错误
解决:修改包名与原来copy的项目包名。
备注:出现此异常的情况较多,以上只是比较少有的一种情况
原创粉丝点击