in my app I need to save some files in the device, to save the file I use:
Environment.getExternalStorageDirectory().getAbsolutePath() + "mypath"
to get the path. This work on almost all the devices but I have some problems in other devices (nexus4 for example..)
the error is:
java.lang.RuntimeException: java.io.FileNotFoundException:
/mnt/sdcard/musicfall/data/cache/.first_activation: open failed: ENOENT
(No such file or directory)
The strange thing is that it works on many device, and for this reason I can't see the problem.
PS: in "mypath" I use mkdir to create the folders that I need
Related
File file = new File(filePath);
InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);
simple piece of code.
i checked the following:
file!=null
file.isFile()
file.exists()
file.canRead()
everything is true. The program have the permission and can actually read this existing file, but put it in a FileInputStream, it throws the following exception:
java.io.FileNotFoundException: /storage/emulated/0/XNR/Setting.gson: open failed: EFAULT (Bad address)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
...
Caused by: android.system.ErrnoException: open failed: EFAULT (Bad address)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7372)
at libcore.io.IoBridge.open(IoBridge.java:478)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
...
it works well only on a api 23 emulator now. maybe the issue is cause by some new mechanics of newer version android api?
funny thing is, i developed and tested it on a android r emulator exclusively 2 months ago and everything is fine, after tested on several actuall devices, the project was deemed done and finished, it sat in my hard drive untouched for 2 months, i can even see the same .gson file generated by it. almost looks like it just went bad on it's own.
Using getFilesDir() or getExternalFilesDir(String) to access storage instead of using Environment.getExternalStorageDirectory() solved the problem, android no longer supports that since q based on the comment above.
I'm seeing this error in the pre-launch report:
Caused by: b.b.a.h.h: Error loading audio file: sounds/mysound.ogg
...
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:332)
The App is working fine on a real device, and also in the emulator. It only seems to show up in the pre-launch report (all devices fail).
Has anyone come across this before?
The following StackOverflow post looks related:
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
However I ran the command unzip -lv MyApplication.apk and it says the sound files are not compressed ("Stored" with 0%).
I also tried explicitly adding
android {
aaptOptions {
noCompress "ogg"
}
}
but to no avail.
Is this a problem with the Firebase emulators? One of the devices listed as failing matches a real device configuration that I have tested as working on a physical device.
Also, I'm using the LibGDX framework. I load the assets in the loading screen like so:
assetManager.load("sounds/mysound.ogg", Sound.class);
And then I get them using:
assetManager.get("sounds/mysound.ogg", Sound.class);
Caused by: java.io.FileNotFoundException: /RecordsKeeper/address/src/main/res/config.properties: open failed: ENOENT (No such file or directory)
I am getting the above error while I run my application. I am not able to load my config.properties file from config.java while I'm running my android application. Although it gets loaded and works fine when I run my library test cases using that config file.
This question already has answers here:
Exception 'open failed: EACCES (Permission denied)' on Android
(34 answers)
Closed 8 years ago.
For some strange reason, am constantly facing an issue with different types of Android devices, for saving the captured images on the device storage.
Here, is the detailed error log, of what, actually am getting.
java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:940)
at com.parkhya.pick_for_shareAflash.HomeActivity.resizeImage(HomeActivity.java:456)
at com.parkhya.pick_for_shareAflash.HomeActivity.onActivityResult(HomeActivity.java:393)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:933)
Although, all the other Android apps, like, Instagram and others, are able to save the camera clicked images on the devices.
Anybody, can you please suggest, what should I do, in order for my app, to save the camera pictures in sdcard.
This may help you. I face the same issue when writing the file on sdcard. I have set all required permission to write the file but I used the file object like below:
Wrong:
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+fileName);
Correct:
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), fileName);
That means the path was wrong.
Solution what i find is
edit the Emulator
1. go to android virtual device manager and then edit the emulator
2. set say 100 MB for Sd card for the respected emulator and say Ok
3. save and close emulator and start
4. path saved is click DDMS mnt/sdcard/yourfilename
it worked for me the app is not giving Error and is working
I'm getting an error on the following line of code:
FileInputStream is = new FileInputStream("/sdcard/DCIM/ROBIN.jpg");
The error is:
java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)
But the image is present in the directory
My USB connection is Charge only
Never hardcode paths like /sdcard. For example, /sdcard is wrong on most Android devices. Use Environment.getExternalStorageDirectory() to find the root of external storage.
Make sure you have set the permission WRITE_EXTERNAL_STORAGE in your manifest.