Results 1 to 20 of 23
- 05-08-2008, 07:30 AM #1
Member
- Join Date
- May 2008
- Posts
- 5
- Rep Power
- 0
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
CheersLast edited by jeer; 05-08-2008 at 08:15 AM.
- 05-08-2008, 07:56 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What ArrayListTest class doing there in your application?
- 05-08-2008, 07:58 AM #3
working fine in my system:
where is ArrayListTest classi am the future
- 05-08-2008, 08:13 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, he has something wrong with that class. Seems to he used some class libraries which are not supported with currently working version.
- 05-08-2008, 08:16 AM #5
Member
- Join Date
- May 2008
- Posts
- 5
- Rep Power
- 0
Sorry, that is HashMapTest
- 05-08-2008, 08:18 AM #6
Oh man, you have edited the compilation error :p
i am the future
- 05-08-2008, 08:22 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In that case, your code is ok. Except that you work out correctly on the Student object. Constructor parameters...
- 05-08-2008, 08:33 AM #8
Member
- Join Date
- May 2008
- Posts
- 5
- Rep Power
- 0
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
- 05-08-2008, 08:37 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Everything working fine for me. Which Java version you used?
- 05-08-2008, 08:38 AM #10
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 - versioni am the future
- 05-08-2008, 08:40 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Rakesh, you talking to me. If so, now it's useless, because all the things perfect for any version. :)
- 05-08-2008, 08:44 AM #12
@Eranga
Sorry! i replied to jeer :(
i guess he compiled with 1.5 version and running with 1.4 :eek:i am the future
- 05-08-2008, 08:45 AM #13
Member
- Join Date
- May 2008
- Posts
- 5
- Rep Power
- 0
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?
- 05-08-2008, 08:47 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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...;)
- 05-08-2008, 08:53 AM #15
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
- 05-08-2008, 09:01 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 05-08-2008, 09:09 AM #17
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
- 05-08-2008, 09:11 AM #18
Generics i got that
we call it Generics ;)
i am the future
- 05-08-2008, 09:16 AM #19
Member
- Join Date
- May 2008
- Posts
- 5
- Rep Power
- 0
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.
- 05-08-2008, 09:35 AM #20
Similar Threads
-
Stack push/pop/peek operations
By Java Tip in forum Java TipReplies: 0Last Post: 01-29-2008, 09:03 AM -
String operations..
By sireesha in forum New To JavaReplies: 4Last Post: 12-14-2007, 02:04 AM -
Uses unchecked or unsafe operations message
By Robbinz in forum New To JavaReplies: 2Last Post: 12-06-2007, 10:56 PM -
UnChecked Exception
By Java Tip in forum Java TipReplies: 0Last Post: 11-18-2007, 07:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks