NullPointerException URLImageSource.getConnection(URLImageSource - java

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

Related

Java creates temp folder with shortened path and throws 'Not found' exception when trying to access files placed in it

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.

How to use Jason with JEdit on Mac

I'm just starting out with Jason (agent-oriented language) and having problems running some code. It gives me the following error:
I'm pretty new to this so not really sure what to do next. This is the path information from Jason:
I can tell the problem is related to the path of the Java Home, but I don't know what to change it to. I'm using Mac by the way.
Any help is appreciated!
Regarding the problem of "The path to the jason.jar file (...) was not correctly set:...", in "Plugins -> Plugins Options -> Jason", you have to set the path to "jason-X.Y.jar" location. You pointed it to "jedit.jar", just change it to "/libs/jason-2.4.jar".
You also may be asked to fix ant path. In this case, point it to the folder "/libs".

IllegalArgumentException when running app. (Android)

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.

Cannot convert project: C:\workspace_IntelliJ\Main\new-webapp\.idea\workspace.xml: Error on line 1: Content is not allowed in prolog

I have no clue what suddenly have happened. I restarted my Idea workspace and it popped up the following error:
Cannot convert project: C:\workspace_IntelliJ\Main\new-webapp.idea\workspace.xml: Error on line 1: Content is not allowed in prolog.
What does this error mean? I have checked my workspace.xml. Whenever I try to open it in an editor it displays the following (I believe it's broken):
nulnulnul
I have no clue what to change and how to fix this thing. Any help on this would be great!
Just remove workspace.xml file. It worked for me ;)
Ok, I fixed the problem (not sure yet why the file got broken though).
Step1: I created a new workspace and copied my source files and .idea files excluding workspace.xml. Infact I deleted it before copying it to new workspace.
It worked! guess deleting and re-creating was the option
It looks like this problem can be fixed by opening up the .idea/workspace.xml file in a text editor and saving it specifically with UTF-8 encoding. This is possible using Sublime Text for example. This fixed the problem for me.

Having trouble with java packages/setting classpath

I usually don't have any problems setting up the classpath and running programs, but I'm running into a bit of a problem. I'm working on a program that will download a series of reports. If the working directory is called Report downloader, my project resides in
src/org/report/reportdownloader
and the jar files I'm working with reside in
lib/
When I'm going to compile my project (I'm in windows :( ) I type in
javac -classpath .;..\..\..\..\..\lib.transfer.jar; ..\..\..\..\..\lib.someotherjar.jar; ReportGrabber.java ReportDriver.java
I get an error message saying
ReportDriver.java:12: error:package com.transfer does not exist
import com.transfer.*;
^
1 error
And I don't really understand why. I'm trying to import a valid package, and I showed it where to find the jar in the classpath and it's still giving me grief.
I'm losing my mind, I feel so dumb for asking about this. I could give up and just use eclipse but I really want to figure this out.
EDIT: When I type
java -cp .;..\..\..\..\lib\transfer.jar; ..\..\..\..\lib\someotherjar.jar; ReportDriver
to run the file, I get an error saying
Error: could not find or load main class ..\..\..\..\lib\someotherjar.jar;
Any ideas?
Why are there 5 .. instead of 4?
to access your lib directory from reportdownloader, you have to do
..\..\..\..\lib
not
..\..\..\..\..\lib
Using a relative path seems like a bad idea to me.
Why not do this:
... -classpath /lib/transfer.jar /lib/someother.jar
or in windows:
... -classpath c:\lib\transfer.jar c:\lib\someother.jar

Categories

Resources