|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-08-2008, 08:30 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 5
|
|
|
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 09:15 AM.
|
|

05-08-2008, 08:56 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
|
What ArrayListTest class doing there in your application?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 08:58 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
|
working fine in my system:
where is ArrayListTest class
__________________
Life was much better in 2021
|
|

05-08-2008, 09:13 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
|
Yep, he has something wrong with that class. Seems to he used some class libraries which are not supported with currently working version.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 09:16 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 5
|
|
|
Sorry, that is HashMapTest
|
|

05-08-2008, 09:18 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
Oh man, you have edited the compilation error 
__________________
Life was much better in 2021
|
|

05-08-2008, 09:22 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
|
In that case, your code is ok. Except that you work out correctly on the Student object. Constructor parameters...
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 09:33 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 5
|
|
|
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, 09:37 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
|
Everything working fine for me. Which Java version you used?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 09:38 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
|
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
__________________
Life was much better in 2021
|
|

05-08-2008, 09:40 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
Rakesh, you talking to me. If so, now it's useless, because all the things perfect for any version. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 09:44 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
|
@Eranga
Sorry! i replied to jeer
i guess he compiled with 1.5 version and running with 1.4 
__________________
Life was much better in 2021
|
|

05-08-2008, 09:45 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 5
|
|
|
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, 09:47 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
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...
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 09:53 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
i don't think JAVA code compiled with 1.5 will run using 1.4 version ( for all cases ) may be i am wrong.
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 
__________________
Life was much better in 2021
|
|

05-08-2008, 10:01 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
|
|
Originally Posted by rjuyal
i don't think JAVA code compiled with 1.5 will run using 1.4 version ( for all cases ) may be i am wrong. 
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. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-08-2008, 10:09 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
HashMap<String,Object> h
this feature was not in 1.4 
in 1.4 we have to write:
HashMap h
BTW, i don't remember what do we say this feature <String,Object>
__________________
Life was much better in 2021
|
|

05-08-2008, 10:11 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
|
Generics i got that
we call it Generics 
__________________
Life was much better in 2021
|
|

05-08-2008, 10:16 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 5
|
|
|
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, 10:35 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
|
|
|
__________________
Life was much better in 2021
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|