我的很多用户在实例化内容描述符时都面临 NullPointerException 问题。
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.UriMatcher.mText' on a null object reference
at android.content.UriMatcher.addURI(UriMatcher.java:186)
at com.getsuperapp.chat.db.ContentDescriptor.getUriMatcher(SourceFile:25)
at com.getsuperapp.chat.db.DatabaseProvider.query(SourceFile:33)
at android.content.ContentProvider.query(ContentProvider.java:1017)
at android.content.ContentProvider$Transport.query(ContentProvider.java:238)
at android.content.ContentResolver.query(ContentResolver.java:497)
at android.content.ContentResolver.query(ContentResolver.java:439)
可以找到设备和环境的集合here .
ContentDescriptor 文件是
/**
* A few constants from other classes used in the file
*
* from UserTable.java
* public static final String PATH = "user_table";
* public static final int PATH_TOKEN = 10;
*/
public class ContentDescriptor {
private static UriMatcher URI_MATCHER = null;
private static Uri BASE_URI = null;
public static UriMatcher getUriMatcher(Context appContext) {
String AUTHORITY = appContext.getPackageName() + ".quickblox";
if (URI_MATCHER == null) {
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
//The line below is throwing the exception.
URI_MATCHER.addURI(AUTHORITY, UserTable.PATH, UserTable.PATH_TOKEN);
URI_MATCHER.addURI(AUTHORITY, DialogTable.PATH, DialogTable.PATH_TOKEN);
URI_MATCHER.addURI(AUTHORITY, MessageTable.PATH, MessageTable.PATH_TOKEN);
URI_MATCHER.addURI(AUTHORITY, ChatInfoTable.PATH, ChatInfoTable.PATH_TOKEN);
}
return URI_MATCHER;
}
public static Uri getBaseUri(Context appContext) {
String AUTHORITY = appContext.getPackageName() + ".quickblox";
if (BASE_URI == null) {
BASE_URI = Uri.parse("content://" + AUTHORITY);
}
return BASE_URI;
}
}
如果您需要任何进一步的信息,请告诉我。任何人都可以让我对此有所了解。最后我无法重现崩溃。
编辑
伙计们不要在不阅读的情况下将其刷入任何其他 NPE 类别。它可以毫无问题地在许多设备上运行。初始化参数是常量。其崩溃所在的行也在代码中进行了注释。
最佳答案
您的 AUTHORITY、PATH 和 PATH_TOKEN(所有这些)的值是多少?根据值和 Android 版本,应用程序在您的应用程序上运行可能属于 bug fixed in UriMatcher .我想这就是您想开始挖掘的地方。另外,您是否收到来自开发者控制台或某个错误报告之王的错误报告?如果是,什么 Android 版本有共同的报告?它可能有助于重现故障。或者获取大量运行在不同版本上的设备/模拟器并尝试手动获取它。
关于android - ContentDescriptor 在实例化时抛出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38691613/