很多我的用戶在實例化內容描述符時面臨NullPointerException問題。ContentDescriptor在實例化時拋出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類別此不讀。它運行在很多設備上沒有麻煩。初始化參數是常數。代碼中也會對其崩潰的行進行註釋。
可能重複[什麼是NullPointerException,以及如何解決它?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-doi-i-fix - ) – Jens
謝謝,但它不是真的。這個問題隱藏在aosp的內容描述符中。我想深入瞭解爲什麼會發生這種情況。如果您需要閱讀代碼,則實例化將傳遞常量,所以問題與輸入無關。 – humblerookie
模型類中的一個靜態字段(PATH或PATH_TOKEN)將爲空。確保他們沒有任何修改。此外,您可能想要爲這些字段使用getters/setters。 – Shaishav