#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Detroit
    Posts
    0
    Rep Power
    0

    Question Problems compiling/Running Java Apps and Applets


    Greetings all,

    I am running Redhat Linux 7.2 and installed both the J2SDK and J2RE 1.4.0 from SUN via .rpm

    I setup my PATH to accomodate my tools, javac etc but it looks like my CLASSPATH is wrong.

    vi Test.java

    public class Test {
    public static void main( String args[] )
    {
    System.out.println( "Testing..." );
    }
    }

    javac Test.java
    java Test.class
    Exception in thread "main" java.lang.NoClassDefFoundError; Test/class

    What do I have to do?

    I tried

    java -cp /home/mydir/Test.class

    and it spits out a list of switch options.


    This is what happens when I try an applet

    vi HelloWorld.java

    import java.applet.*;
    import java.awt.*;

    public class HelloWorld class extends Applet {
    public void paint(Graphics g) {
    g.drawString("Hello World!", 50, 25);
    }
    }

    vi Hello.html

    <HTML>
    <HEAD>
    <TITLE>Hello Applet</TITLE>
    </HEAD>
    <BODY>
    <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>

    javac HelloWorld.java

    HelloWorld.java:4: '{' expected
    public class HelloWorld class extends Applet {

    HelloWorld.java:8: '{' expected
    }
    3 errors


    Thanks in advance for your help
  2. #2
  3. No Profile Picture
    Java Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    5
    Rep Power
    0
    Hi,

    Don't put the ".class" bit in
    i.e.
    java Test
    OR
    java /home/mydir/Test

    Though you'll probably have other CLASSPATH type problems, but this'll get you past the current error. Mind you, if the compile worked it probably has access to the stuff it needs. Give it a go...

    Oscagne
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Detroit
    Posts
    0
    Rep Power
    0
    Doh!

    Thanks.
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    India
    Posts
    7
    Rep Power
    0
    u have included class keyword in two places...


    public class HelloWorld class extends Applet -- wrong

    public class HelloWorld extends Applet -- right

    --aabha

IMN logo majestic logo threadwatch logo seochat tools logo