{"record":{"id":"c63c9bb6fdb451c5","repo":"didi/DoKit","slug":"last-path-segment-is-not-a-resource-id-data-u","errorCode":null,"errorMessage":"Last path segment is not a resource ID: \" + data.uri","messagePattern":"Last path segment is not a resource ID: \" \\+ data\\.uri","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"warning","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java","lineNumber":348,"sourceCode":"  }\n\n  static int getResourceId(Resources resources, Request data) throws FileNotFoundException {\n    if (data.resourceId != 0 || data.uri == null) {\n      return data.resourceId;\n    }\n\n    String pkg = data.uri.getAuthority();\n    if (pkg == null) throw new FileNotFoundException(\"No package provided: \" + data.uri);\n\n    int id;\n    List<String> segments = data.uri.getPathSegments();\n    if (segments == null || segments.isEmpty()) {\n      throw new FileNotFoundException(\"No path segments: \" + data.uri);\n    } else if (segments.size() == 1) {\n      try {\n        id = Integer.parseInt(segments.get(0));\n      } catch (NumberFormatException e) {\n        throw new FileNotFoundException(\"Last path segment is not a resource ID: \" + data.uri);\n      }\n    } else if (segments.size() == 2) {\n      String type = segments.get(0);\n      String name = segments.get(1);\n\n      id = resources.getIdentifier(name, type, pkg);\n    } else {\n      throw new FileNotFoundException(\"More than two path segments: \" + data.uri);\n    }\n    return id;\n  }\n\n  static Resources getResources(Context context, Request data) throws FileNotFoundException {\n    if (data.resourceId != 0 || data.uri == null) {\n      return context.getResources();\n    }\n\n    String pkg = data.uri.getAuthority();","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java#L330-L366","documentation":"In Utils.getResourceId(Resources, Request), a single-segment android.resource:// URI is interpreted as a raw numeric resource ID (Integer.parseInt of the one segment). If the segment is not a number (e.g. a bare resource name like 'ic_logo'), the NumberFormatException is caught and rethrown as FileNotFoundException('Last path segment is not a resource ID: <uri>') — the single-segment form only accepts IDs, not names.","triggerScenarios":"Passing android.resource://com.example.app/ic_logo — a one-segment path containing a resource NAME instead of a number; passing a numeric string with whitespace or a '#'/hex prefix.","commonSituations":"Assuming the short form accepts names like the two-segment form does; passing Integer.toHexString(resId) or a formatted string ('res 2131099687') as the segment.","solutions":["Use the two-segment name form: android.resource://<package>/drawable/ic_logo.","Or pass the decimal ID as a string: android.resource://<package>/2131099687 (String.valueOf(resId)).","Best for local resources: pass the int directly via picasso.load(resId)."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource://com.example.app/ic_logo\"); // name, not ID\npicasso.load(uri).into(imageView);\n\n// after\nUri uri = Uri.parse(\"android.resource://com.example.app/drawable/ic_logo\");\npicasso.load(uri).into(imageView);","handlingStrategy":"validation","validationCode":"Uri resourceUri(Context ctx, String type, String name) {\n    return new Uri.Builder().scheme(\"android.resource\")\n        .authority(ctx.getPackageName())\n        .appendPath(type).appendPath(name).build(); // 2-segment name form\n}","typeGuard":null,"tryCatchPattern":"Catch in error callback; the message includes the URI so mis-built segments are easy to spot in logs.","preventionTips":["Single-segment form accepts decimal IDs only; names need the two-segment form.","Pass String.valueOf(resId) when using the short form.","Validate one-segment URIs with a numeric regex before loading."],"tags":["android","picasso","uri","resource","parsing"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}