Note that there are some explanatory texts on larger screens.

plurals
  1. POUriMatcher not recognizing pattern
    text
    copied!<p>I'm having trouble with matching URIs in my <code>ContentProvider</code>. It will match paths with one or two "tags" (not sure what the correct term is), for example it can recognize <code>box/#</code>. But as soon as I add a second tag, for example <code>box/#/item</code>, I throw an <code>InvalidArgumentException</code> and my app crashes. I've read in several threads on here that this issue can sometimes be solved by changing the order of the URIs added to the <code>UriMatcher</code>; I tried this, but to no avail. Anyone know what the problem is? I've excerpted relevant parts of my code below.</p> <p>From my <code>ContentProvider</code>:</p> <pre><code>private static final String AUTHORITY = "com.example.boxdatabase.DatabaseProvider"; // Type of query public static final int BOXES = 100; ... public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); ... // URI Matcher for queries private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH); static { sURIMatcher.addURI(AUTHORITY, "box/#/item", BOX_ITEM); sURIMatcher.addURI(AUTHORITY, "box/#/item/#", BOX_ITEM_ID); sURIMatcher.addURI(AUTHORITY, "box", BOXES); sURIMatcher.addURI(AUTHORITY, "box/#", BOXES_ID); sURIMatcher.addURI(AUTHORITY, "item", ITEMS); sURIMatcher.addURI(AUTHORITY, "item/#", ITEMS_ID); } </code></pre> <p>An example of where I try to access my <code>ContentProvider</code> and it fails:</p> <pre><code>return new CursorLoader(this, Uri.withAppendedPath( DatabaseProvider.CONTENT_URI, "box/" + boxId + "/item"), DatabaseContract.BoxItemEntry.ALL_COLUMNS, null, null, null); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload