i recently made a java project and couldnt run its jar file in an attempt to find the problem i made another project with this code
:::
import javax.swing.*; import java.awt.*; public class test extends JFrame { public test () { super("test"); setSize(100,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); FlowLayout flo = new FlowLayout(); setLayout(flo); } public static void main(String[] args) { test eas = new test(); } }
i cant run that jar either
plz help
Offline
Maybe you don't have JRE installed?
Offline
i have JRE7
Offline
You should have JDK as well.
Offline
jji7skyline wrote:
You should have JDK as well.
That shouldn't affect anything if he's just trying to run a JAR though...
Offline
You are trying to use test() as a class when test() is a method. Instead of
test eas = new test()
Just do
test()
Also, it doesn't seem to loop. If you don't loop, the window will probably just open and close immediately, because the program will end execution. So try a while(true) loop in void main().
Last edited by 16Skittles (2012-09-03 09:01:03)
Offline
16Skittles wrote:
You are trying to use test() as a class when test() is a method. Instead of
Code:
test eas = new test()Just do
Code:
test()Also, it doesn't seem to loop. If you don't loop, the window will probably just open and close immediately, because the program will end execution. So try a while(true) loop in void main().
test() is a constructor not a method. I see no problems in your code so it is probably just a compiler problem.
Offline
poopo wrote:
16Skittles wrote:
You are trying to use test() as a class when test() is a method. Instead of
Code:
test eas = new test()Just do
Code:
test()Also, it doesn't seem to loop. If you don't loop, the window will probably just open and close immediately, because the program will end execution. So try a while(true) loop in void main().
test() is a constructor not a method. I see no problems in your code so it is probably just a compiler problem.
Ah. Well, if it is in a jar it is a .class file, right? You didn't try to pack a .java file in there, did you? Also do you have the meta-inf stuff there? In most IDEs it is automatically added, but I don't know what your setup is.
Offline
the program is a .java..how do i change tht
Offline
theprogrammerpro wrote:
the program is a .java..how do i change tht
There is your first problem. You need to compile it into a .class file using the java compiler. In command line, type
javac theProgramName.java
Where "theProgramName" is the name of your .java file (it is case sensitive as well, so if you named the file "HelloWorld.java" and in the console typed "helloworld.java" it would not work.
Offline
16Skittles wrote:
theprogrammerpro wrote:
the program is a .java..how do i change tht
There is your first problem. You need to compile it into a .class file using the java compiler. In command line, type
Code:
javac theProgramName.javaWhere "theProgramName" is the name of your .java file (it is case sensitive as well, so if you named the file "HelloWorld.java" and in the console typed "helloworld.java" it would not work.
done still not working
Offline
I used netbeans
Offline
So now you've compiled it? What is the extension of the file now?
Offline
I have one .java one . Class and a .jar
Offline
First try in the command line
java (nameofyourfile)
Do not add .class at the end of this, it already assumes that it is a .class file. You shouldn't be worrying about a .jar for something this simple.
Offline
16Skittles wrote:
First try in the command line
Code:
java (nameofyourfile)Do not add .class at the end of this, it already assumes that it is a .class file. You shouldn't be worrying about a .jar for something this simple.
it says it cant find or load the class file
Offline
theprogrammerpro wrote:
16Skittles wrote:
First try in the command line
Code:
java (nameofyourfile)Do not add .class at the end of this, it already assumes that it is a .class file. You shouldn't be worrying about a .jar for something this simple.
it says it cant find or load the class file
oh, make sure you do
cd (directory name)
so that you are in the correct directory. For example, if the class is at C:\users\theprogrammerpro\java and if cmd starts in C:\users\theprogrammerpro then you would need to do
cd java
and then do the other code.
Offline
Same thing my project is in my docs under username so what would be the full code
Offline
theprogrammerpro wrote:
Same thing my project is in my docs under username so what would be the full code
what is the full directory name? like C:/... I probably can't help you because I'll be leaving for a week but someone else should be able to help you.
Last edited by 16Skittles (2012-09-03 22:59:39)
Offline
C:\Users\Me\Documents\NetBeansProjects\test\build\classes
Offline
theprogrammerpro wrote:
C:\Users\Me\Documents\NetBeansProjects\test\build\classes
so try
cd NetBeansProjects\test\build
Offline