#Making a Training Tool and getting Compiler Errors
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @frail wigeon! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
I have looked at Stack Overflow and stuck it in ChatGPT and nothing
private JLabel createIcon(String imagePath, int x, int y) {
try {
BufferedImage image = ImageIO.read(new File(imagePath));
if (image == null) {
System.out.println("Failed to load image: " + imagePath);
return null;
}
ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
label.setSize(100, 100);
label.setLocation(x, y);
label.addMouseListener(new DragAndDropListener());
return label;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Maritime.main(MARITIME.java:90)
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Probably just a wrong path. Try using the absolute path to the image first. If that workd chrck that your relazive path is correct
Whats line 90
ok
Line 90 down:
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new Maritime();
});
}
Can you share the full stacktrace
And the stacktrace ?
PS C:\Users\trcoo> & 'C:\Program Files\Java\jdk-20\bin\java.exe' '--enable-preview' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\trcoo\AppData\Local\Temp\vscodesws_6c664\jdt_ws\jdt.ls-java-project\bin' 'Maritime'
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Maritime.main(MARITIME.java:90)
That's it ?
Other than the possible path issue it should work.
I thought so too!
I mean yeah the code crashes when the paths are not correct but other than that it should work
ran it on a linux box (kali) and get errors:
I have changed the directory to:
I have stripped it back to 1 file to test at the moment
and chmod it!
I have uploaded it to my GITHUB: https://github.com/CtrlAltT0m/ShipDragandDrop
does it need double \
Lets imagine this is your project structure
Project
--src
----Maritime.java
--Picutres
----Picture1.png
----Picture2.png
...
Then the correct relative path would be: Pictures/Picture1.png.
The error indicates that your method createIcon returned a null value. As I said that happens when the path is wrong.
Could you share your project structure ?