Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java on XP

Options
  • 24-03-2002 11:15pm
    #1
    Registered Users Posts: 8,503 ✭✭✭


    Can somebody please tell me how to set java properly on XP. I'm using jdk1.3.1. I cant get it to work, it wont complie programs I keep getting an error exception in "main". Also it wont read my class files, eg Console.class.


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Can you write out the whole error message?

    Are you declaring your main as...

    public static void main(String[] args)


  • Registered Users Posts: 8,503 ✭✭✭Makaveli


    yes.
    I'll post up the error when I get home.
    It's something like exception in thread "main" then I cant remember the rest.


  • Closed Accounts Posts: 11 V3n37


    I suppose you already know that when you run a java program you should not include the file extension of the byte code file. If you have a "proggie.class" then running it "java proggie" only, no extension.

    I had a similar problem that my jdk wouldn't run any class files. That was after I installed JBuilder. However removing JBuilder and reinstalling JRE (Java Runtime Environment) fixed it.


  • Registered Users Posts: 1,176 ✭✭✭podgeen


    I doubt its a problem with XP, you probably have'nt setup you classpath. We'll know for sure when u paste up the error.


  • Registered Users Posts: 8,503 ✭✭✭Makaveli


    The thing is though I have java working on win98, but it doesnt work on my new computer which is xp.


  • Advertisement
  • Registered Users Posts: 8,503 ✭✭✭Makaveli


    Ok here is the error. The program compiles but when I run it I get this.

    Exception in thread "main" java,lang.NoClassDefFoundError: test

    that's the test program I'm using

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


    When I try to compile something using Console.class I get the error message
    cannot resolve symbol
    variable console


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    OK, let's try and sort out the most common problem ever known to Java programmers: java.lang.NoClassDefFoundError
    Oh that ba$tard child is always picking on somebody.

    OK, I am going to go to extreme basics, but use this as a template for future attempts...

    STEP 1 [Write the Code]
    public class myClass{

    public static void main(String args[]){
    System.out.println("Hello, World");
    }
    } // eo myClass


    Save the above file as myClass.java

    STEP 2 [Check and/or initialise your environment settings, Eg. CLASSPATH]
    @ the command/DOS prompt type: echo %CLASSPATH%
    If it's blank you must set it up. To do this type: SET CLASSPATH = [JAVA_HOME]\lib\tools.jar;.
    JAVA_HOME = where you installed the jdk (possibly c:\jdk1.3.1 in your case). tools.jar is the base include JAR for java that lets you do all the foundation stuff of the language. Anything after that is extra APIs/J2EE/J2ME etc.

    To verify that CLASSPATH has been setup correctly remember to type: echo %CLASSPATH%, and it should show up correctly. Also I put a '.' (dot) at the end of your classpath which refers to the current directory. This means that you dont have to use the -cp command line argument for each call to java.exe

    STEP 3 [Compile your code]
    What I have done on my system is also set the PATH variable to point to [JAVA_HOME]\bin, this lets me call java/javac etc from any directory. The reason you do all this is to save typing, and make sure that everything can find everything else if it needs to. I have a batch file run automatically, every time I open a command line window, so I never have to worry about this kind of stuff again. IF I ever want to use extra APIs I simply append them to the CLASSPATH entry in the batch file.

    Now simply type: javac myClass.java, it should compile without errors. If it throws compile time errors recheck that you;ve done everything right so far.

    STEP 4 [Run your program]
    This is the easy part. All you have to do is type: java myClass. If you haven't got the current dir appended to your classpath it will throw a class not found exception in main (like you've already seen). You can either append it like I have done above, or instead type: java -cp %CLASSPATH%;. myClass. Tis up to you.

    All going well you should sit back in awe as the words "Hello, World" grace your command window.

    Hopefully this will eliminate the problem for a few of yez

    ;-phobos-)


  • Registered Users Posts: 8,503 ✭✭✭Makaveli


    Thanks for all your help Phobus. It turns out that the only problem was that I didnt put in the "." at the end of the classpath.

    So this is my classpath anyway and it works

    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;c:\jdk1.3.1\bin\;c:\jdk1.3.1.;


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    First and foremost you are welcome, you're problems may be solved, but did you learn anything from what I said.
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;c:\jdk1.3.1\bin\;c:\jdk1.3.1.;

    That my friend is not a CLASSPATH, that looks more like a PATH. Which are completely different things.

    Anyway if it was a classpath it doesn't point to the current directory anywhere. I am guessing the "c:\jdk1.3.1.;" part is where you thought you had it. That should have been "c:\jdk1.3.1;.". If it was a PATH variable. You can use directory listings to point to libraries, but for debugging purposes you are much better off specifying the JAR names. That way you will clearly be able to see what you are using, when you type: echo %CLASSPATH%

    And this completely baffles me, what the hell is a Phobus?? :rolleyes:

    ;-phobos-)


  • Registered Users Posts: 8,503 ✭✭✭Makaveli


    Sorry I meant phobos it was a typo.
    I also meant path not classpath, although when I echo classpath that's what I get.
    Anyway it works, so it will have to do for now.
    What I did learn is that it's a headache setting stuff up :)


  • Advertisement
  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Setting Stuff Up

    You're dead right, it is a pain in the a$$. When you read all the Java programming books in the world you would think implementing what you've learned is the hardest part. I can assure you it's not. I have delved in to a lot of Java oriented stuff. I'm far from an expert because I don't spend enough time in a particular area for that kind of thing. But what I have noticed is that setting up the correct development/runtime environments have brought me the most trouble. And sometimes it's too late in the development cycle before these issues are brought to your attention. :rolleyes:

    Also if it works, good stuff. But I still think it's fluke (unfortunately). Let's hope it doesn't give you problems when you need to do something different in the future. ;)

    ;-phobos-)


Advertisement