Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

string to HashMap error Java

Posted on 2007-11-29
5
Medium Priority
?
2,588 Views
Last Modified: 2011-09-20
Hi All,

I am having issues with this , I hope u guys can help me out
<% java.util.HashMap searchHash = new java.util.HashMap();%>
<%String selectedvalue = request.getParameter("var"); //
 String selectedfield = request.getParameter("selectedfield");%>
   
  <% searchHash.put(selectedfield,selectedvalue);
 
  System.out.println("value:"+(java.util.HashMap)searchHash.get(selectedfield));  /// ERROR , java.lang.ClassCastException

Can you tell me why? I am really confused

Thanks in advance
0
Comment
Question by:prk_usa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 27

Assisted Solution

by:mrcoffee365
mrcoffee365 earned 600 total points
ID: 20379963
Your HashMap doesn't return a HashMap, it returns a String.  So cast the result of searchHash.get to (String) .
0
 
LVL 92

Accepted Solution

by:
objects earned 900 total points
ID: 20379975
you don't really need to cast it at all.

  System.out.println("value:"+searchHash.get(selectedfield));
0
 

Author Comment

by:prk_usa
ID: 20379979
Tanks for u r response mrcoffee365.
I am not following you, I am sorry.

but

searchHash.get(selectedfield));  ---> returning String

I want this to be type casted to HashMap , because I have to pass thi into a function, and that function accepts

HashMap only
0
 
LVL 92

Expert Comment

by:objects
ID: 20379987
> because I have to pass thi into a function, and that function accepts

then just pass your hashmap, eg.

myMethod(searchHash);
0
 

Author Comment

by:prk_usa
ID: 20380010
oh ok , I will try it out and let you know and Thanks for your response.

 I really appreciate.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question