Solved

string to HashMap error Java

Posted on 2007-11-29
5
2,577 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
  • 2
  • 2
5 Comments
 
LVL 26

Assisted Solution

by:mrcoffee365
mrcoffee365 earned 200 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 300 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
change size of out.write buffer 1 80
Run the project 5 82
console vs log file 16 74
authenticate preemptively soap ui option 3 108
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now