Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008, 08:30 AM
Member
 
Join Date: May 2008
Posts: 5
jeer is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-08-2008, 08:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-08-2008, 08:58 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
working fine in my system:

where is ArrayListTest class
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-08-2008, 09:13 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-08-2008, 09:16 AM
Member
 
Join Date: May 2008
Posts: 5
jeer is on a distinguished road
Sorry, that is HashMapTest
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-08-2008, 09:18 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
Oh man, you have edited the compilation error
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-08-2008, 09:22 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-08-2008, 09:33 AM
Member
 
Join Date: May 2008
Posts: 5
jeer is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-08-2008, 09:37 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-08-2008, 09:38 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-08-2008, 09:40 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-08-2008, 09:44 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
@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
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-08-2008, 09:45 AM
Member
 
Join Date: May 2008
Posts: 5
jeer is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-08-2008, 09:47 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga

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
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-08-2008, 09:53 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-08-2008, 10:01 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,179
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
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
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-08-2008, 10:09 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 05-08-2008, 10:11 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
Generics i got that
we call it Generics
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 05-08-2008, 10:16 AM
Member
 
Join Date: May 2008
Posts: 5
jeer is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 05-08-2008, 10:35 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 100
rjuyal is on a distinguished road
Uses unchecked or unsafe operations message
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stack push/pop/peek operations Java Tip Java Tips 0 01-29-2008 10:03 AM
String operations.. sireesha New To Java 4 12-14-2007 03:04 AM
Uses unchecked or unsafe operations message Robbinz New To Java 2 12-06-2007 11:56 PM
UnChecked Exception Java Tip Java Tips 0 11-18-2007 08:06 PM