This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-09-03 00:41:08

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

java problem

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

:::

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

 

#2 2012-09-03 00:46:36

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: java problem

Maybe you don't have JRE installed?  tongue


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#3 2012-09-03 01:10:20

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

i have JRE7

Offline

 

#4 2012-09-03 01:15:49

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: java problem

You should have JDK as well.


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#5 2012-09-03 01:30:06

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: java problem

jji7skyline wrote:

You should have JDK as well.

That shouldn't affect anything if he's just trying to run a JAR though...


Posts: 20000 - Show all posts

Offline

 

#6 2012-09-03 01:43:02

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

i have JDK

Offline

 

#7 2012-09-03 03:04:52

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: java problem

what error do you get?


http://i.imgur.com/1QqnHxQ.png

Offline

 

#8 2012-09-03 08:59:08

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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().

Last edited by 16Skittles (2012-09-03 09:01:03)


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#9 2012-09-03 11:40:03

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: java problem

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.


http://i45.tinypic.com/28rnqki.jpg

Offline

 

#10 2012-09-03 12:02:44

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#11 2012-09-03 14:33:35

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

the program is a .java..how do i change tht

Offline

 

#12 2012-09-03 14:56:06

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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.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.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#13 2012-09-03 15:16:21

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

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.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.

done still not working

Offline

 

#14 2012-09-03 15:53:13

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

bump

Offline

 

#15 2012-09-03 17:25:11

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: java problem

I have a 1 step process that will solve all your problems:
Get an IDE


http://i45.tinypic.com/28rnqki.jpg

Offline

 

#16 2012-09-03 22:07:26

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

I used netbeans

Offline

 

#17 2012-09-03 22:10:25

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: java problem

So now you've compiled it? What is the extension of the file now?


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#18 2012-09-03 22:14:08

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

I have one .java one . Class and a .jar

Offline

 

#19 2012-09-03 22:21:48

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#20 2012-09-03 22:31:30

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

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

 

#21 2012-09-03 22:47:06

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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

Code:

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

Code:

cd java

and then do the other code.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#22 2012-09-03 22:52:41

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

Same thing my project is in my docs under username so what would be the full code

Offline

 

#23 2012-09-03 22:59:31

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

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)


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#24 2012-09-03 23:05:42

theprogrammerpro
New Scratcher
Registered: 2012-09-01
Posts: 79

Re: java problem

C:\Users\Me\Documents\NetBeansProjects\test\build\classes

Offline

 

#25 2012-09-04 06:44:45

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: java problem

theprogrammerpro wrote:

C:\Users\Me\Documents\NetBeansProjects\test\build\classes

so try

Code:

cd NetBeansProjects\test\build

http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

Board footer