Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:33:56+00:00 2026-06-02T21:33:56+00:00

I am new to Java. My Problem is that my Java program cannot find

  • 0

I am new to Java.

My Problem is that my Java program cannot find the image file im trying to use as
a JButton. (Currently this code does nothing, as I am simply getting a desirable look
first).
THIS IS MY MAIN CLASS

Code:

package mainClasses;
/*
 * Frame Info and all that shit,
 * mainFrame is the actual frame itself
 * it will refer to MainC.java a lot Main class = Main Class
 */
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.io.File;

import resources.ResourcesManager; 

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;


@SuppressWarnings({ "unused", "serial" })
public class mainFrame extends JFrame {

ResourcesManager rManager = new ResourcesManager();


public mainFrame() {
    JButton playButton = new JButton(rManager.pButton);
    JButton infoButton = new JButton();
    JButton exitButton = new JButton();


    int x = 310, y = 300;
    setSize(x, y);
    setVisible(true);
    setLayout(null);
    setTitle("Kingdom Raider");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    /*Buttons and Properties*/
                        /*X,  Y,  X, Y*/
     playButton.setBounds(10, 10, 70, 40);
    /* Add if problem cannot be sorted */ // playButton.setText("Play");



    add(playButton);

     infoButton.setBounds(90, 10, 110, 40);
     infoButton.setText("Information");
    add(infoButton);

     exitButton.setBounds(210, 10, 70, 40);
     exitButton.setText("Exit");
    add(exitButton);

    //This is for checking if the file is here.
    File imageCheck = new File("/JavaGame/src/resources/playButton.png");

    if(imageCheck.exists())
    {
        System.out.println("File found!");
    }
    else 
    {
        System.out.println("File not found!");
    }

    repaint();



}









public void Painting (Graphics g) {


}
}

THIS IS MY RESOURCESMANAGER.JAVA

package resources;

import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class ResourcesManager {

/*Here, your going to want to declare anything
 * needed.
 */

public ImageIcon KRLogo = new ImageIcon("/JavaGame/src/resources/kingdomraiderlogo.png");
public ImageIcon pButton = new ImageIcon("/JavaGame/src/resources/playButton.png");

public void settings() { //Set the stuff settings, locations e.t.c.
    //BLAH

}

}

So basically the Button needs pButton from the ResourcesManager

Which is Practically playButton.png which is located in the resources package,
the same folder as the ResourcesManager.java

Please Help me with my directory issues.

EDIT: SORRY FORGOT, NO ERROR, JUST A BLANK BUTTON COMES UP WITHOUT MY IMAGE.

As for my directory it looks like

src

mainClasses (package)
   mainFrame.java
   runClass.java
resources (package)
   kingdomraiderlogo.png
   playButton.png (image wanted at the momment.)
   ResourcesManager.java

I’ll +1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:34:00+00:00Added an answer on June 2, 2026 at 9:34 pm

    Do it like this:

    public ImageIcon KRLogo = new ImageIcon(Toolkit.getDefaultToolkit().getImage(
    (ResourcesManager.class.getResource("/resources/kingdomraiderlogo.png"))));
    
    public ImageIcon pButton = new ImageIcon(Toolkit.getDefaultToolkit().getImage(
    (ResourcesManager.class.getResource("/resources/playButton.png"))));
    

    Edit:

    In Java you have two ways of accessing files. One way is via the path that uses forward slashes, which is usually used in the getResource() method of the class Class. The first slash referc to the src folder of your project.

    Second way is a pathname and is used in the constructor of the class File, for example. On windows, this then uses double backslashes, because a backslash has to be escaped. Problem is the platform independency, which is easily regained by using File.Separator in the pathname String.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this problem: The type java.awt.image.RenderedImage cannot be resolved. It is indirectly referenced
I'm pretty new to java and I've got a problem that I couldn't solve
My problem is that I cannot find a way to correctly display the correct
I have a problem.... I made a java program that does the following: BufferedReader
I'm trying to write a simple java program in Eclipse that prints these four
I just posted this question: How to distribute my Java program so that it
I cannot figure this problem out. Everything in the program works the way i
I have a Java problem that involves reading a text file and check that
I have a java program that I am trying to generate 3 outputs for,
Okay, so what I'm trying to do is create a java program that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.