unable to locate png from location on pc

try {
image = ImageIO.read(new File("C:\\Users\\mikso\\IdeaProjects\\UPT\\src\\main\\resources\\draggg.png"));
} catch (IOException e) {
e.printStackTrace();
image = null;
}
try {
image = ImageIO.read(new File("C:\\Users\\mikso\\IdeaProjects\\UPT\\src\\main\\resources\\draggg.png"));
} catch (IOException e) {
e.printStackTrace();
image = null;
}
I'm trying to load the image from the path on my pc. If I copy paste the link to my search bar, it opens up the image just fine. Any ideas?
4 Replies
JavaBot
JavaBot7d ago
This post has been reserved for your question.
Hey @taun! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant 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.
taun
taunOP7d ago
JPanel dropPanel = new DropPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(image != null) {
int x = (this.getWidth() - image.getWidth()) / 2;
int y = (this.getHeight() - image.getHeight()) / 2;
g.drawImage(image, x, y, image.getWidth(), image.getHeight(), null);
} else {
g.drawString("Image not found", this.getWidth() / 2 - 50, this.getHeight() / 2);
}
}
};
JPanel dropPanel = new DropPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(image != null) {
int x = (this.getWidth() - image.getWidth()) / 2;
int y = (this.getHeight() - image.getHeight()) / 2;
g.drawImage(image, x, y, image.getWidth(), image.getHeight(), null);
} else {
g.drawString("Image not found", this.getWidth() / 2 - 50, this.getHeight() / 2);
}
}
};
No description
Kyo-chan
Kyo-chan7d ago
What's the stack trace printed?
JavaBot
JavaBot7d ago
Post Closed
This post has been closed by <@239353471285854208>.
Want results from more Discord servers?
Add your server