Java.lang.numberformatexception For Input String Raw /storage/emulated/0/download/ Patched -
: Older versions of libraries like uCrop or flutter_file_picker had bugs where they incorrectly assumed the returned path from the system was a numeric ID.
The error java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/download/..." occurs when your code attempts to convert a file path string into a numeric value (like an int , long , or double ). Since a file path contains letters, slashes, and special characters, it is fundamentally incompatible with numeric parsing.
if (path.startsWith("raw:")) { path = path.replaceFirst("raw:", ""); } // Use the path directly to create a File object File file = new File(path); Use code with caution. 3. Update Your Dependencies : Older versions of libraries like uCrop or
In the context of the Downloads folder on Android, the system sometimes returns a URI that looks like this: raw:/storage/emulated/0/Download/example.pdf
: Code that tries to split a URI and parse the final segment as an integer without validating that it is actually a number. How to Fix the Error 1. Check if the String is Numeric Before Parsing if (path
String id = getDocumentId(uri); if (id.matches("[0-9]+")) { long numericId = Long.parseLong(id); // Proceed with numeric ID logic } else { // Handle it as a raw file path string } Use code with caution. 2. Handle "raw:" Paths Explicitly
A common mistake occurs when developers attempt to extract an ID from this URI. Older Android APIs often returned numeric IDs (e.g., 12345 ), so code was written to parse that string into a Long . When modern Android versions (especially Oreo and later) return the full "raw" file path instead of a numeric ID, the numeric parsing fails because the string now contains non-digit characters. Common Trigger Scenarios How to Fix the Error 1
This specific error is almost exclusively seen in , often appearing within libraries like uCrop , FilePicker , or when manually handling URIs from the Downloads folder. Why the Error Happens