JAVA : cannot find class JFrame?
hi everyone :)
i'm a linux newbie who's only installed mandrake 9.2 a few months ago.... the problem is, i'm trying to javac this .java file i made to try to understand java gui application, and i got an error message saying Cannot locate class "JFrame" i've imported javax.swing.*, java.io.*, java.awt.*; and the only class in the file extends JFrame. i tried looking around and heard some stuff about classpath, but i still don't know anything. can anybody help? thanks :) |
just a tip
I think you need to set your CLASSPATH.. or you could try typing javac while you are in the directory where the binary(executable) is stored.. try looking in BIN directories..
HOPE this helped.. could you look also at my post and help me with JDBC problem.. i used jcreator to program in java and use microsoft access database thru ODBC.. id appreciate any suggestion you could give me.. to find my post just search for JAVA.. the title of my post is JDBC problem...... |
I think by default that classes like awt and swing are included in the classpath.
Could you post your code? |
Code:
import javax.swing.*; any help is greatly appreciated >_< thank you! |
Hi
Using eclipse the following code works Quote:
Dirk |
how were u able to run it using eclipse ... am new to java ... can u tell me wht Run configuration to use
thanks in advance |
isolated the problem some more. i couldn't import JFrame in javax.swing
but i could import anything in java.awt, and i'm guessing most of the other libraries as well. in javax/swing/ there is a JFrame.h file, but that's it. um.......anybody help? ^^;;;;;;; i tried removing import javax.swing.JFrame AND "extends JFrame" and it compiled. thanks :) |
Hi
I was able to compile it or Eclipse does it automatically, when saving the file. It doesn't contain a main method ;) In order to run it under Eclipse it's just go to Run/Run As/Java Application. I recommend take a look on the Eclipse SDK. Especially for Java beginners, Eclipse has nice editing features like auto completion, rename, auto import selector and lot more. Just go to http://www.eclipse.org and download the latest stable release and unix examples for Linux. If you're using Gnome or KDE select the GTK version. Installation is even easier: change to root and cd to /opt. Do a unzip <dist.package> and unzip eclipse-example.... as user just change to /opt/eclipse and start ./eclipse Take time and make familiar with the GUI (there's a tutorial within the product). Dirk |
Purely out of curiosity but what java sdk hava you got installed and where did you get it from?
|
Your code is mostly fine (it compiles properly as is), the problem is with your Java installation. Make sure you have the Sun Java SDK 1.2 or greater.
Here's your code, modified to run properly (it compiled before, just didn't run properly): Code:
import javax.swing.*; |
ummm thanks for the code :) i learn some stuff too but the problem is not the code. i think i have java 1.4 or something like that, i'll check again when i'm from that computer. but as i said, the problem is specifically in JFrame, since import javax.swing.*; didn't return any compilation error.
neither is any of the classes in awt. read my previous posts for more info :P do i need to set a classpath? thanks... |
The exact version is displayed via java -version
In most cases you do not need to set the classpath, except you're using libraries, that are not under $JAVA_HOME/ and it's subdirectories. Dirk |
All times are GMT -5. The time now is 12:17 PM. |