一、使用AndroidStudio
在logcat中查看实时日志,需要选择连接的手机和应用包名
AS下载链接
二、使用adb shell dumpsys dropbox命令获取
#!/bin/bash
# path="/data/system/dropbox" # 在手机这个目录下存储了崩溃日志
newest_time=$(adb shell dumpsys dropbox | grep 'data_app_crash' | awk 'END {print $1,$2}')
adb shell dumpsys dropbox --print ${newest_time}
# echo -e "时间是:${newest_time}"
三、使用adb+logcat获取
# 清除日志,日志内容很多,对于能毕现的日志,可以先清除后重新获取
adb logcat -c
# 然后再次运行崩溃操作,再抓取日志
# 存储日志到当前目录下的 carsh.log 中
adb logcat -d *:W > crash.log
# W指的是警告以上日志
# 这个日志文件包含了所有打印的日志,需要自己筛选下崩溃日志,比如搜索 begin、crash、Exception
# 为了更精确的筛选日志,可以加入筛选条件
adb logcat -d *:W grep "包名" >E:\crashlog2.txt
四、获取无响应ANR的日志
# 在/data/anr/目录下存储所有了ANR日志(Application Not Responding)
adb pull /data/anr/ ~/Downloads
五、常见的异常汇总
NullPointerException:指针为空异常java.lang.NullPointerException: Attempt to invoke virtual method ‘…’ on a null object reference
ClassCastException:类型转换异常java.lang.ClassCastException: … cannot be cast to …
IllegalArgumentException:非法参数异常java.lang.IllegalArgumentException: … is not a valid argument
IllegalStateException:非法状态异常java.lang.IllegalStateException: … is not in a valid state
IndexOutOfBoundsException:越界异常java.lang.IndexOutOfBoundsException: Index … out of bounds for length …
OutOfMemoryError:内存溢出错误java.lang.OutOfMemoryError: Failed to allocate a … byte allocation with … free bytes and …MB until OOM, target footprint …MB, growth limit …MB
NoSuchMethodError:方法不存在错误java.lang.NoSuchMethodError: … method not found
ArithmeticException:算术异常java.lang.ArithmeticException: … / by zero
SecurityException:安全异常java.lang.SecurityException: … not allowed to perform operation
NetworkOnMainThreadException:主线程网络异常android.os.NetworkOnMainThreadException
InflateException:布局解析异常android.view.InflateException: Binary XML file line #…: Error inflating class …
ResourcesNotFoundException:资源未找到异常android.content.res.Resources$NotFoundException: Resource ID #… not found
SQLiteDatabaseLockedException:SQLite数据库锁定异常android.database.sqlite.SQLiteDatabaseLockedException: database is locked
SQLiteException:SQLite数据库异常android.database.sqlite.SQLiteException: … error code …
StaleDataException:数据过期异常android.database.StaleDataException: Attempted to access a cursor after it has been closed.
VerificationError:验证错误java.lang.VerifyError: … access … from incompatible class …
AssertionError:断言错误java.lang.AssertionError: … assertion failed
NoSuchAlgorithmException:加密算法不存在异常java.security.NoSuchAlgorithmException: … algorithm not available
SocketException:Socket异常java.net.SocketException: … failed: ECONNREFUSED (Connection refused)
SSLException:SSL异常javax.net.ssl.SSLException: … SSL handshake aborted
FileNotFoundException:文件未找到异常java.io.FileNotFoundException: … (No such file or directory)
IOException:IO异常java.io.IOException: … (Connection timed out)
ParseException:解析异常java.text.ParseException: Unparseable date: “…”
JSONException:JSON解析异常org.json.JSONException: … at character …
SAXException:SAX解析异常org.xml.sax.SAXException: … at line …
NumberFormatException:数字格式化异常java.lang.NumberFormatException: For input string: “…”
IllegalStateException:线程状态异常java.lang.IllegalStateException: Cannot execute task: the task is already running.
ConcurrentModificationException:并发修改异常java.util.ConcurrentModificationException: … (java.util.ConcurrentModificationException)
UnsupportedOperationException:不支持的操作异常java.lang.UnsupportedOperationException: … not supported
InterruptedException:线程中断异常java.lang.InterruptedException: sleep interrupted
RuntimePermission:权限异常java.lang.RuntimePermission: … permission required
AuthenticationException:认证异常org.apache.http.client.ClientProtocolException: … (authentication challenge)
FileNotFoundException:未找到文件异常java.io.FileNotFoundException: … File not found.
UnsupportedOperationException:不支持的操作异常java.lang.UnsupportedOperationException: … not supported
EOFException:文件结尾异常java.io.EOFException: … end of file reached
ConnectException:连接异常java.net.ConnectException: … Connection refused
SocketTimeoutException:Socket超时异常java.net.SocketTimeoutException: … Read timed out
JNIException:Java本机接口异常java.lang.reflect.InvocationTargetException: JNI Exception: …
NoSuchProviderException:提供程序不存在异常java.security.NoSuchProviderException: Provider … not found
Surface.OutOfResourcesException:Surface资源耗尽异常android.view.Surface$OutOfResourcesException: … (Surface with no valid EGLContext)
WindowManager.BadTokenException:无效的Window Token异常android.view.WindowManager$BadTokenException: … is not valid; is your activity running?
TimeoutException:超时异常java.util.concurrent.TimeoutException: … timeout
SSLHandshakeException:SSL握手异常javax.net.ssl.SSLHandshakeException: … SSL handshake aborted
SAXParseException:SAX解析异常org.xml.sax.SAXParseException: … at line …
IllegalStateException:未知的Bundle标记异常java.lang.IllegalStateException: Unknown Bundle Marker at position …: …
IllegalArgumentException:传递了错误的方位坐标java.lang.IllegalArgumentException: Point (?, ?) must be in the range ? <= x <= ? and ? <= y <= ?
SQLiteReadOnlyDatabaseException:SQLite只读数据库异常android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write to a readonly database
SQLException:SQL异常java.sql.SQLException: … SQL exception
ZipException:压缩文件异常java.util.zip.ZipException: … Not in GZIP format
DifferentKeyException:与此密钥不相关的密钥异常java.security.spec.InvalidKeySpecException: Inappropriate key specification: Different key pair generated for given keyUsageInfo
六、参考链接
50个Android开发中常见的异常崩溃情况
Android崩溃日志获取方式