When running my project, I get this error.
Error:java.lang.IllegalArgumentException: Invalid resource path: C:\Android\Source Code and Samples\turbo-editor-master\turbo-editor-master\app\src\main\res
Any idea what is causing this?
I am using source code from the Turbo Editor app and have done no changes to the app prior to running it.
Try two things:
- Clean your project. This helps most of the times
- Go to the directory mentioned in the Exception. Make sure it actually exists.
I found the error. While looking at the error, follow the path that it is referring to. If there is no path like that, or a file missing, then create it and move the file to that path. Should fix the problem.
Illegal argument exception is throwed when a function gets wrong (it cannot reasonably deal with it) argument. This can be caused by, for example, missing function that was somewhere overrided. In your case - maybe this is issue with path? I'm not sure but if the path exists you can try changing it so it does not have "spaces" and capital letters. Please dump complete log with error.
Related
so I did run into one very weird issue. The idea is simple: create temp dir, place some files in it and then try to access them. Now the problem is that calling File.createTempDir() or Files.createTempDirectory(prefix) creates new file inside AppData/Local/temp with shortened path, so the full path to folder looks something like C:/Users/FirstNam~1/AppData/Local/Temp/myFolder/myFile.txt instead of C:/Users/FirstName LastName/AppData/Local/Temp/myFolder.myFile.txt.
The difference is that generated path inside java contains FirstNam~1 instead of FistName SecondName. Java then throws exception File Not Found.
When I try to copy and paste shortened path into file explorer I get an error saying that file does not exist, but if I do change shortened path to full one then file opens and it works as intended.
Is there any way to fix it? Ether by forcing java to use full path names or enabling something in windows? I did Enable NTFS long paths policy, but it did not help.
This is happening when using java 8/11 and windows 10 running on VM, project is using AGP and gradle. Temp file is created inside groovy file that extends Plugin<Project>
Just when I lose hope and create a ticket, couple hours after that I find the answer. So, java has method Path.toRealPath() which solves this ~1 issue. After using this method paths no longer contain shortening and are correctly resolved.
EDIT: looks like java is doing everything correct and paths are actually valid, problem did come from library that I'm using and it's a bug with it.
here is the screenshothere is the screenshot error
please help me solve this error for e to deploy our system this week.
It cannot find the file specified. The error is right there, FileNotFoundException.
Things to look into to remedy this.
1) Is the file actually there
2) Does java have access to that folder or are their access restrictions on it
3) Did you type the path correctly, looks like you are using unescaped windows style \ slashes which java doesn't like (thought it should have thrown the error earlier
Try looking at some of those errors. For more information on the FileNotFoundException https://docs.oracle.com/javase/7/docs/api/java/io/FileNotFoundException.html?is-external=true
I am using this code
String path = getClass().getResource("Template.xls").getPath();
When I run it on my machine (windows), everything is good. I even did system.out.println on the get resource part and on the get path part and the results were:
file:/C:/Eclipse/Netbeans/SoftwareCom/build/classes/assets/Template.xls
/C:/Eclipse/Netbeans/SoftwareCom/build/classes/assets/Template.xls
However I am getting the following error reports from some users
java.nio.file.InvalidPathException: Illegal char <:> at index 4:
file:\C:\Software%20Com\SoftwareCom.exe!\assets\Template.xls
Iam not sure whats happening or why would it work for some and not others
Any pointers?
To answer this question properly, it would be helpful to know what you want to do with the path information. To read the file, you don't need the path.
You could just call
getClass().getResourceAsStream("Template.xls")
If you really want to know the path, you should call
URL url = getClass().getResource("Template.xls");
Path dest = Paths.get(url.toURI());
This might cause problems as you seem to pack your java files in a windows executable. See Error in URL.getFile()
Edit for your comment:
As I wrote above, you don't need the path of the source to copy. You can use
getClass().getResourceAsStream("Template.xls")
to get the content of the file and write the content to whereever you want to write it. The reason for failing is that the file in your second example is contained within an executable file:
file:\C:\Software%20Com\SoftwareCom.exe
as can be seen from the path:
file:\C:\Software%20Com\SoftwareCom.exe!\assets\Template.xls
The exclamation mark indicates that the resource is within that file.
It works within Netbeans because there the resource is not packed in a jar, but rather is a separate file on the filesystem.
You should try to run the exe-version on your machine. It will most likely fail as well. If you want more information or help, please provide the complete code.
I faced this same issue and go around it by using the good ol' File API
URL url = MyClass.class.getClassLoader().getResource("myScript.sh");
Path scriptPath = new File(url.getPath()).toPath();
And it worked!
i'm programming a project in IntelliJ IDEA on my Mac OSX. Everything works just fine when i run the code or when i export the jar and run it. But when i switch to windows, i get an error saying this:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:116)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:126)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
I really cannot imagine, what causes that error, cause all ressources are stored in the "res" folder, which is marked as a resource folder (Also some other images are loaded successfully).
The error happens in the last of this code snippet:
System.out.println("Starting new Frame");
Variables.theFrame = new JFrame("AudioTaggerUI");
Variables.theFrame.setContentPane(new AudioTaggerUI().getContentPane());
Variables.theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Variables.theFrame.pack();
I hope anyone of you can help me ^^
Check if there are any hardcoded path names (with file separators)
Okay, i solved the Problem by myself. This line threw (indirectly) the Error:
Variables.theFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("/gui/icon.png")));
I changed the line to this one:
Variables.theFrame.setIconImage(getToolkit().getImage(Image.class.getResource("/gui/icon.png")));
Thanks # all for your help
I'm trying to open files from within Java with something like this:
java.awt.Desktop.getDesktop().open(new File("c:\\coolfile.txt");
Of course it all works fine and dandy in most cases.
HOWEVER!
When I have a file with the unicode character u3000, I cannot open it! Even if the file exists.
For example:
java.awt.Desktop.getDesktop().open(new File("c:\\coolfile\u3000withweirdname.txt");
I get an Exception, EVEN WHEN THE FILE EXISTS
[java] java.io.IOException: Failed to open file:/E:/_prog/test%E3%80%80.txt. Error message: The system cannot find the path specified.
Please help me i tried pretty much everything. This is driving me insane :/
Edit:
To give some more info:
I can easily create file with this name from Java.
It seems it has something to do with whitespace
I don't know if it applies to other characters; I didn't find any yet. But of course if there's 1 there could easily be 100.
I'm pretty sure I can't read from the file or write to it from Java, but I haven't tested that since it isn't my main concern.
java.awt.Desktop.getDesktop().open(new File("c:\\coolfile\u3000withweirdname.txt");
That doesn't compile. Clearly it isn't your real code.
[java] java.io.IOException: Failed to open
file:/E:/_prog/test%E3%80%80.txt
And there is proof. Clearly you passed a URL to new FileInputStream(). It doesn't take a URL string, it takes a file name.
Ok i think i actually found a kind of solution to my question and i post it here to help any people that may have similar problems.
This fix only works for Windows (XP and up i think) BUT i don't even know if this problem exist in other OS. And even if it does a similar fix should be possible.
I am using the following code to succesfully open a file with the character:
Process p = new ProcessBuilder("cmd", "/c start \"\" \"E:\_prog\test\u3000.txt\"").start();
Which opens the file 'E:_prog\testu3000.txt'
As far as i know \u3000 is ideographic space character. To test your code I created a file with name CompanyAlt+3000Address.
Note: when you press Alt+3000, windows will create an ideographic space character. Then I copied the file name, to my java program and it worked for me.
Desktop.getDesktop().open(new File("C:\\Users\\Chandru\\Desktop\\Companyâ••Address.txt"));