Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    jeer is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default HashMapTest.java uses unchecked or unsafe operations.

    Hi

    I am new to Java. m using HashMap class.
    when i compile "javac HashMapTest.java", i get following error:
    Note: HashMapTest.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    I was using:
    HashMap h= new HashMap();

    I made some changes in my code
    import java.util.*;
    public class HashMapTest {
    public static void main(String[] args) {
    // creating HashMap object
    HashMap<String,Object> h= new HashMap<String,Object>();
    // creating Student objects
    Student s1 = new Student ("ali" , 1);
    // adding elements (Student objects) where roll nos
    // are stored as keys and student objects as values
    h.put("one", s1);
    ............
    ........
    .....

    Now, after compile, there is no error but when i run my code then there is following exception:
    Exception in thread "main" java.lang.UnsupportedClassVersionError: HashMapTest
    (Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)


    Please guide me to resolve this error
    Cheers
    Last edited by jeer; 05-08-2008 at 08:15 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    working fine in my system:

    where is ArrayListTest class
    i am the future

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yep, he has something wrong with that class. Seems to he used some class libraries which are not supported with currently working version.

  5. #5
    jeer is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    Sorry, that is HashMapTest

  6. #6
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    Oh man, you have edited the compilation error :p
    i am the future

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In that case, your code is ok. Except that you work out correctly on the Student object. Constructor parameters...

  8. #8
    jeer is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    My Student class looks fine, following is the code:

    public class Student {
    private String name;
    private int rollNo;
    // Standard Setters
    public void setName (String name) {
    this.name = name;
    }
    // Note the masking of class level variable rollNo
    public void setRollNo (int rollNo) {
    if (rollNo > 0) {
    this.rollNo = rollNo;
    }else {
    this.rollNo = 100;
    }
    }
    // Standard Getters
    public String getName ( ) {
    return name;
    }
    public int getRollNo ( ) {
    return rollNo;
    }
    // Default Constructor
    public Student() {
    name = "not set";
    rollNo = 100;
    }
    // parameterized Constructor for a new student
    public Student(String name, int rollNo) {
    setName(name); //call to setter of name
    setRollNo(rollNo); //call to setter of rollNo
    }
    // Copy Constructor for a new student
    public Student(Student s) {
    name = s.name;
    rollNo = s.rollNo;
    }
    // method used to display method on console
    public void print () {
    System.out.print("Student name: " +name);
    System.out.println(", roll no: " +rollNo);
    }
    } // end of class

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  10. #10
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    set

    JAVA_HOME to the directory having latest JDK version

    also
    in your path variable replace all occurence of older path to new one.


    one more thing, what do it return
    java - version
    i am the future

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Rakesh, you talking to me. If so, now it's useless, because all the things perfect for any version. :)

  12. #12
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default @Eranga

    Sorry! i replied to jeer :(

    i guess he compiled with 1.5 version and running with 1.4 :eek:
    i am the future

  13. #13
    jeer is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    I have installed jdk1.5.0_14.
    I have already included "C:\Program Files\Java\jdk1.5.0_14\bin;" in path environment variable.
    how can i set JAVA_HOME?

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default


    I thought it's for me. :)

    What the point with 1.4 Rakesh. Only the HashMap he used in advanced. But it support from 1.2. So...;)

  15. #15
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    i don't think JAVA code compiled with 1.5 will run using 1.4 version ( for all cases ) may be i am wrong. :confused:

    if he have used some methods which were only in 1.5 , and not in 1.4 in that case it should certainly not run :confused:
    i am the future

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by rjuyal View Post
    i don't think JAVA code compiled with 1.5 will run using 1.4 version ( for all cases ) may be i am wrong. :confused:
    You are 100% correct. May be confused with my last replay. What I try to say is this.

    Some functions(libraries and so..) on later versions are not supported in newer versions. Basically Suns' deprecate them newer versions in different way. Only such thing I can see from our original code is the HashMap, supported from 1.2 and I think my numbers are correct. :)

  17. #17
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    HashMap<String,Object> h

    this feature was not in 1.4 :cool:
    in 1.4 we have to write:

    HashMap h


    BTW, i don't remember what do we say this feature <String,Object>
    i am the future

  18. #18
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default Generics i got that

    we call it Generics ;)
    i am the future

  19. #19
    jeer is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    I am compiling and running my code using same java version. if i use
    HashMap h
    then there following error:
    Note: HashMapTest.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

  20. #20
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

Page 1 of 2 12 LastLast

Similar Threads

  1. Stack push/pop/peek operations
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 09:03 AM
  2. String operations..
    By sireesha in forum New To Java
    Replies: 4
    Last Post: 12-14-2007, 02:04 AM
  3. Uses unchecked or unsafe operations message
    By Robbinz in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 10:56 PM
  4. UnChecked Exception
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-18-2007, 07:06 PM

Posting Permissions

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