• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Swing not working ...

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Im very new to Java and I am doing a simple 'Hello World' swing tutorials as follows:



When i run the HelloWorldSwing.java file it pops up the code in Notepad instead of the expected JFrame ...

What have i overlooked ??

Cheers for any help

Paul
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do u mean it pops up the code in Notepad?How r u running ur program? Plz specify
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im running it from DOS in a console from c:/sun/appserver/jdk/bin using java c:\<path>\file.java

and then it just opens the code in notepad ?

Seems that the swing libraries dont kick into action ?

Does that help clear it up at all ?

Cheers for your help!!!

Paul
 
Amirthalingam Prasanna
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Well first of all you are not compiling your program.From the directory try
in the commmand prompt:
javac <filename>.java

This will compile and give you a class file called HelloWorld.class
after than to run you program in the command prompt type:
java HelloWorldSwing

If any problem shoot back on this thread
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey mate,

ooppss...should have cleared that up...I have compiled it..in my dir I have HelloWorldSwing.class and HelloWorldSwing.java ...

I used javac c:\sun\appserver\jdk\bin HelloWorldSwing.java to compile and get the .class file...then i run java c:\sun\appserver\jdk\bin\<working dir>\HelloWorldSwing.java

This is where i get the apparent error ...notepad popping up and no JFrame window as expected.

Im quite confused...

Cheers mate...hope to hear from yuo soon

Paul
 
Amirthalingam Prasanna
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are running it wrong buddy:

It shdn't be:
java c:\sun\appserver\jdk\bin\<working dir>\HelloWorldSwing.java

It shd be:
java c:\sun\appserver\jdk\bin\<working dir>\HelloWorldSwing

No .java when u r using java.....(i mean when u r running)

cheers
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i do that i get


Any clues ?

thanks again mate

Paul
 
Amirthalingam Prasanna
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try first going into ur working directory first
and then type

java HelloWorldSwing

If it says

--------------------------------------------------------------------------------

'HelloWorldSwing' is not recognised as an internal or external command, operable program or batch file.

--------------------------------------------------------------------------------
then u r not typing the java word...try again and see. It has nothing to with ur code.The problem is in the way u r running the program buddy
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okey dokey...i think we're getting somewhere ...

Im in my working directory and i type: java HelloWorldSwing

and i get the following:


Does that make the problem obvious to you ?? as it just makes me more confused lol

cheers again mate..appreciate your help!!

Paul
 
Amirthalingam Prasanna
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its running perfectly in my machine...
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do i have to anything to 'enable' swing ??

Im totally clueless as to what may have gone wrong ?
 
Amirthalingam Prasanna
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing to enable...
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does this error code lead you to any ideas ??



cheers mate
[ June 14, 2004: Message edited by: Jim Yingst ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul - when you put something in code tags, please make sure the line contains line breaks. Otherwise you get a really long line that makes the rest of the page virtually unreadable. That is, it forces the whole page to be really wide, and we have to use the horizontal scrollbar to read each line. Ugh! Thanks.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Paul!

That error occurs due to an improper change to a class. For instance say class A uses B.method. If B.method is changed but the corresponding invocation in class A is not, the latter will continue on calling the previous method, but because it was not recompiled the compiler doesn't warn you. NoSuchMethodError will be thrown by the JVM.

Because of the variety of problems you have experience so far, the best you can do is to delete all the classes in that directory and compile the program again.
 
Paul Moran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim:

Sorry about that one mate...my bad...wont happen again

Jose:

I have just deleted the two class files from my working dir. After i recompile, I get the two class files (as expected) ...when i go to run the program, I still get these errors

I have a page here that I am using to help troubleshoot this annoying error:
http://www.vfxtalk.com/java_page.htm

Appreciate any help you can give...this really is getting quite annoying

Cheers

Paul
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it and it worked fine for me. What version of java are you using? (type java -version to find out). My guess is that you are not using a version that is 1.4 or greater. Here is how I figured it out:

The error says NoSuchmethodError and gives you line 12 in your code.
line 12 is this:
JFrame.setDefaultLookAndFeelDecorated(true);
A quick check of the javadocs for Jframe.setDefaultLookAndFeelDecorated() says:
"Since: 1.4 "
Which means this method was added starting at 1.4.
This means any JVM before 1.4 won't have that method and would give you a NoSuchMethodError.

So, either take out that line, or upgrade to a 1.4 or better JVM (I recommend upgrading)

brian
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's working ok for me.

Try to see if the classpath enviroment variable is pointing to a directory in which an old incompatible copy of HelloWorldSwing.class inhabits. That would make to load the untrusted class before the one you really want.

Such class could also be causing troubles in the extensions directory "C:\j2sdk1.4.2_04\jre\lib\ext"

You can see which are the classes really loaded via the option "-verbose:class" to java command.
In the output look for "[Loaded HelloWorldSwing]". The absence of path means it was loaded from the current directory.
 
reply
    Bookmark Topic Watch Topic
  • New Topic