Reputation: 104
Error : E/FileSource: Failed to open file 'android.resource:/com.android.grafika/2130968577'. (No such file or directory)
String vidAddress = "android.resource://"+getPackageName()+"/"+R.raw.b_right;
Uri vidUri = Uri.parse(vidAddress);
File sliders = new File(vidUri.toString());
Log.d("File",sliders.toString());
How to fix it? and what is the root cause? I mean what is wrong with this code snippet?
Upvotes: 3
Views: 5393
Reputation: 402
final String uriPath="android.resource://"+getPackageName()+"/raw/texivedio";
Upvotes: 0
Reputation: 12214
The problem is the file path you constructed does not exist.
To open raw resources, use openRawResource(). For example:
InputStream stream = getContext().getResources().openRawResource( R.raw.b_right );
Upvotes: 1
Reputation: 1007286
I mean what is wrong with this code snippet?
First, passing the string representation of a Uri
to the File
constructor will never work. A Uri
has a scheme; the File
constructor will not know what to do with the scheme.
Second, the android.resource
scheme is for an Android resource. While resources are files on your developer machine, they are not files on the Android device and cannot be represented by a File
object.
How to fix it?
Do not attempt to access a resource via a File
object.
For example, you can call openRawResource()
on a Resources
object to get an InputStream
on your raw resource, given the resource ID.
Upvotes: 2