This question is edited to include everything asked. New picture links will be added below.
My program runs fine in NetBeans, and cannot load the program when running from its jar file, compiled by NetBeans. I'm compiling on Java 1.6_45, which is simply for compatibility, since this a school-oriented program, for older machines that hardly ever receive any upgrades or updates.
Anyhow, because the program never loaded when I tried it as a .jar file, I was concerned and looked up manual ways to make the jar run. I tried the command prompt command java -jar PhysicsEquations.jar , which I copied straight into my Users folder so I wouldn't have to worry about classpaths.
This is the error message I get (below, first link), an IllegalArgumentException. I'm not sure what to do, and I've researched for a couple of days now trying different things. I'm up for retrying anything though if it could be better explained.
Here is the entire EquationImage class (just a couple lines, bear with me, please). In other code, all I do with it is call the constructor, such as EquationImage fma = new EquationImage("fma.jpg");
and then use setBounds(x,y,width,height);
to add it to a panel that's added to my CardLayout with all of the equations.
package physicsequations;
...
public class EquationImage extends JPanel {
public EquationImage() {
}
public EquationImage(String filename) {
try {
System.out.println(filename);
imageBuffer = ImageIO.read(getClass().getResourceAsStream("images/" + filename));
}
catch(IOException e) {
JOptionPane.showMessageDialog(null, "EquationImage could not find/load the file \n" + filename, "Error Message", JOptionPane.PLAIN_MESSAGE);
}
}
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
graphics.drawImage(imageBuffer, 0, 0, null);
}
private BufferedImage imageBuffer = null;
}
As notable in the code, and the error message, the constructor does receive a filename. In NetBeans, the compiler is able to find all of the images correctly. However, in the jar that I get using 'Clean and Build', it can vary whether or not I actually see a JOptionPane with the error.
I was asked to provide filepaths that I have for my code.
In the project, I have the folder PhysicsEquations. PhysicsEquations has folders dist, build, nbproject, and src. PhysicsEquations also has files build, and manifest.mf.
src has the folder physicsequations, the package that EquationImage is in.
physicsequations then has five files and a folder 'images'. The files are Main, EquationPanel, EquationImage, BadInputException, and Variable.
images has all of my pictures, including Physics.jpg, which is the icon I use in Main:
String imagePath = "physics.jpg";
InputStream imgStream = Main.class.getResourceAsStream("images/" + imagePath);
BufferedImage myImg = null;
try {
myImg = ImageIO.read(imgStream);
}
catch(IOException e) {
JOptionPane.showMessageDialog(null, "The program has failed to load file physics.jpg from the source package.", "Error Message", JOptionPane.ERROR_MESSAGE);
}
setIconImage(myImg);
In the jar itself, I open up the jar and have 2 folders: META-INF and physicsequations. In the folder physicsequations, there are 101 class files, and a folder called images. That folder has all 17 of my pictures used in the project. Below is the text of the manifest.mf document in META-INF from the jar. (Can someone explain to me why it says 1.8? I have 1.6 in my project properties...)
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_31-b13 (Oracle Corporation)
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
Main-Class: physicsequations.Main
https://i.stack.imgur.com/IqgzE.jpg
https://i.stack.imgur.com/rHaDa.jpg
https://i.stack.imgur.com/j5Npw.jpg
https://i.stack.imgur.com/Yt2O3.jpg
I'm hoping all of the links will submit since it says I have limit with 10 rep.