Android常见错误汇编

来源:互联网 发布:淘宝天下小二 培训 编辑:程序博客网 时间:2024/04/30 00:01

Android常见错误汇编

 

目标

该文档主要用于收集,归纳和整理日常Android开发中经常碰到的错误。包括编译错误,运行性错误,非运行性错误和ANR。目前整理不全,以后会在不断开发中逐步完善该篇文档。

 

 

一、编译错误

 

 

 

 

二、运行时错误

1. android.app.Fragment$InstantiationException报错

1)根据报错提示“make sure class name exists, is public, and has an empty constructor that is public”,若Fragement定义有带参构造函数,则一定要定义public的默认的构造函数。即可解决此问题。如果硬要携带参数进去,可以通过Intent结合Bunble的方式携带进去。

2)在“is public, and has an empty constructor that is public” 都满足的情况下,编译ENG版本运行没有任何问题,但是编译USER版本就会出现CRASH错误。报错log信息如下:

E/AndroidRuntime( 3253): FATAL EXCEPTION: mainE/AndroidRuntime( 3253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.SubSettings}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.settings.mcwill.McWiLLSettings: make sure class name exists, is public, and has an empty constructor that is publicE/AndroidRuntime( 3253):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1964)E/AndroidRuntime( 3253):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)E/AndroidRuntime( 3253):     at android.app.ActivityThread.access$600(ActivityThread.java:126)E/AndroidRuntime( 3253):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1155)E/AndroidRuntime( 3253):     at android.os.Handler.dispatchMessage(Handler.java:99)E/AndroidRuntime( 3253):     at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 3253):     at android.app.ActivityThread.main(ActivityThread.java:4482)E/AndroidRuntime( 3253):     at java.lang.reflect.Method.invokeNative(Native Method)E/AndroidRuntime( 3253):     at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 3253):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)E/AndroidRuntime( 3253):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)E/AndroidRuntime( 3253):     at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 3253): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.settings.mcwill.McWiLLSettings: make sure class name exists, is public, and has an empty constructor that is publicE/AndroidRuntime( 3253):     at android.app.Fragment.instantiate(Fragment.java:581)E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.switchToHeaderInner(PreferenceActivity.java:1120)E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.switchToHeader(PreferenceActivity.java:1136)E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:532)E/AndroidRuntime( 3253):     at com.android.settings.Settings.onCreate(Settings.java:99)E/AndroidRuntime( 3253):     at android.app.Activity.performCreate(Activity.java:4465)E/AndroidRuntime( 3253):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)E/AndroidRuntime( 3253):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)E/AndroidRuntime( 3253):     ... 11 more E/AndroidRuntime( 3253): Caused by: java.lang.ClassNotFoundException: com.android.settings.mcwill.McWiLLSettingsE/AndroidRuntime( 3253):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)E/AndroidRuntime( 3253):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)E/AndroidRuntime( 3253):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)E/AndroidRuntime( 3253):     at android.app.Fragment.instantiate(Fragment.java:571)E/AndroidRuntime( 3253):     ... 18 more W/ActivityManager(  422):   Force finishing activity com.android.settings/.SubSettingsW/ActivityManager(  422):   Force finishing activity com.android.settings/.Settings

该类错误原因在于USER版本编译时会代码混淆。解决办法:

在对应模块的proguard.flags文件中引入该Fragment所在的类包即可。比如:

-keep class com.android.settings.wifi.*Settings



 


 

 

 

 

三、非运行时错误

 

 

 

 

四、ANR(Application Not Responding)

 

 

 

 

原创粉丝点击