Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: JDK won't work

  1. #1
    Join Date
    Apr 2008
    Beans
    79

    Exclamation JDK won't work

    Hey All

    I'm trying to work on a java project, but my JDK seems to be messed up. It gives me errors in simple hello world programs or when I do things like create new objects, etc. I've been working with java for a little while now, so I know that there's no errors in the code it's compiling. I installed it with
    Code:
     sudo apt-get install sun-java6-jdk
    I'm getting frustrated with it because I'm pressed for time with this project but can't code. Can anyone tell me why my JDK isn't working?
    Thanks a lot.

  2. #2
    Join Date
    Nov 2007
    Location
    New Zealand
    Beans
    1,026
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: JDK won't work

    Quote Originally Posted by the_real_fourthdimension View Post
    Hey All

    I'm trying to work on a java project, but my JDK seems to be messed up. It gives me errors in simple hello world programs or when I do things like create new objects, etc. I've been working with java for a little while now, so I know that there's no errors in the code it's compiling. I installed it with
    Code:
     sudo apt-get install sun-java6-jdk
    I'm getting frustrated with it because I'm pressed for time with this project but can't code. Can anyone tell me why my JDK isn't working?
    Thanks a lot.
    A few things to check.

    Code:
    java -version
    javac -version
    Can you post back the output.

    Also, are you using an IDE? If so you need to check that the IDE is pointing to the correct java complier and runtime.

  3. #3
    Join Date
    Apr 2008
    Beans
    79

    Re: JDK won't work

    Thanks.
    Code:
    me@my-machine:~$ java -version
    java version "1.6.0_06"
    Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
    Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)
    me@my-machine:~$ javac -version
    javac 1.6.0_06
    Yeah, I thought it might be just the IDE, but I've tried three of them and compiling via the command line with the same results. Import statements aren't working, creating new objects gives me compile errors, etc.

  4. #4
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: JDK won't work

    Quote Originally Posted by the_real_fourthdimension View Post
    Yeah, I thought it might be just the IDE, but I've tried three of them and compiling via the command line with the same results. Import statements aren't working, creating new objects gives me compile errors, etc.
    Please post a simple hello world you wrote, where you put that file, which command you use for compiling in which directory, which errors you get (please copy&paste) and the contents of your CLASSPATH variable.

  5. #5
    Join Date
    Apr 2008
    Beans
    79

    Re: JDK won't work

    Well, I removed java and purged/reinstalled it again, and now object creation and almost everything else works... the only thing that is still giving me trouble is importing. When I try to import the Sacnner class (http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html), I get
    Code:
    The import java.util.Scanner cannot be resolved
    Is the version of JDK I got working too old to use Scanner?
    Thanks.

  6. #6
    Join Date
    Nov 2007
    Location
    New Zealand
    Beans
    1,026
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: JDK won't work

    Quote Originally Posted by the_real_fourthdimension View Post
    Well, I removed java and purged/reinstalled it again, and now object creation and almost everything else works... the only thing that is still giving me trouble is importing. When I try to import the Sacnner class (http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html), I get
    Code:
    The import java.util.Scanner cannot be resolved
    Is the version of JDK I got working too old to use Scanner?
    Thanks.
    Your using JDK 6, right? So no its not too old.

    Do you get this above problem when compiling at the command line?

  7. #7
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: JDK won't work

    How did you install java?

    The following should work and set every thing up correctly. First, install
    Code:
    sudo apt-get install sun-java6-jdk
    And set up
    Code:
    sudo update-java-alternatives -s java-6-sun
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  8. #8
    Join Date
    Apr 2008
    Beans
    79

    Re: JDK won't work

    Compiling this from the command line:
    Code:
    import java.util.Scanner;
    public class test1 {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner();
    }
    
    }
    gives me this:
    Code:
    test1.java:5: cannot find symbol
    symbol  : constructor Scanner()
    location: class java.util.Scanner
    Scanner sc = new Scanner();
                 ^
    1 error
    In eclipse:
    Code:
    The import java.util.Scanner cannot be resolved.
    Scanner cannot be resolved to a type.
    and in geany:
    Code:
    cannot find symbol
    symbol: constructor Scanner()
    location: class java.util.Scanner
    Scanner sc = new Scanner();
    ^
    I used the suggested method to reinstall java before posting this.
    Thanks for all the help. I'm really hoping that I'm just making some stupid mistake that is easy and quick to fix...

  9. #9
    Join Date
    Nov 2007
    Location
    New Zealand
    Beans
    1,026
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: JDK won't work

    Quote Originally Posted by the_real_fourthdimension View Post
    Compiling this from the command line:
    Code:
    import java.util.Scanner;
    public class test1 {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner();
    }
    
    }
    gives me this:
    Code:
    test1.java:5: cannot find symbol
    symbol  : constructor Scanner()
    location: class java.util.Scanner
    Scanner sc = new Scanner();
                 ^
    1 error
    In eclipse:
    Code:
    The import java.util.Scanner cannot be resolved.
    Scanner cannot be resolved to a type.
    and in geany:
    Code:
    cannot find symbol
    symbol: constructor Scanner()
    location: class java.util.Scanner
    Scanner sc = new Scanner();
    ^
    I used the suggested method to reinstall java before posting this.
    Thanks for all the help. I'm really hoping that I'm just making some stupid mistake that is easy and quick to fix...
    Scanner doesnt have a default constructor.

    http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html

    Try using one of the parameterised constructors

    E.g.
    Code:
    new Scanner(System.in);
    In eclipse this should show up in the "Problems" view.
    Last edited by tinny; July 31st, 2008 at 04:53 AM.

  10. #10
    Join Date
    Apr 2008
    Beans
    79

    Re: JDK won't work

    Thanks! Now geany and the terminal compile it correctly. Eclipse, however, still gives me the same errors it gave me before. The same errors it gave me when I had tried to use the scanner class with an older version of java. Is it possible that it's pointing to an older version of java? How do I update it's path?
    Thanks a lot! I feel stupid for those earlier mistakes, but at least they were easliy fixed.

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •