This content has been marked as final.
Show 5 replies
-
1. Re: Help on java.lang.ClassCastException: java.lang.String
jaikiran Oct 19, 2006 3:03 AM (in response to scout1lacno)select o.strCountry from TblCountry as o
o.strCountry appears to be a column of type String. So the returned objects will be of type java.lang.String. Your code:TblCSCSubCategory region = (TblCSCSubCategory) myList.get(i) ;
will have to be changed to:String country = (String) myList.get(i);
-
2. Re: Help on java.lang.ClassCastException: java.lang.String
scout1lacno Oct 19, 2006 6:14 AM (in response to scout1lacno)
Hi Jaikiran,
Have tried your advice on:String country = (String) myList.get(i);
I have changed my code to:for (int i = 0; i < length; i++) { //TblCountry region = (TblCountry) myList.get(i) ; String country = (String) myList.get(i); System.out.println(country); }
But it return an error. The error is:java.lang.ClassCastException: [Ljava.lang.Object; crm.ui.servlets.CountryBean.processRequest(CountryBean.java:46) crm.ui.servlets.CountryBean.doGet(CountryBean.java:70)
Thankz in advance :)
Keith -
3. Re: Help on java.lang.ClassCastException: java.lang.String
jaikiran Oct 19, 2006 6:25 AM (in response to scout1lacno)java.lang.ClassCastException: [Ljava.lang.Object;
crm.ui.servlets.CountryBean.processRequest(CountryBean.java:46)
Check line numbered 46 in the CountryBean. Looks like its casting an Object[] to something else. -
4. Re: Help on java.lang.ClassCastException: java.lang.String
scout1lacno Oct 19, 2006 6:29 AM (in response to scout1lacno)
Line 46 is this:
String country = (String) myList.get(i);
My full code is:protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); TblCountryFacadeLocal myCountryBean = lookupTblCountryFacade(); List myList = myCountryBean.findAllCat(); int length = myList.size(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet CountryBean</title>"); out.println("</head>"); out.println("<body>"); for (int i = 0; i < length; i++) { //TblCountry region = (TblCountry) myList.get(i) ; String country = (String) myList.get(i); System.out.println(country); } /*for (Iterator iter = myList.iterator(); iter.hasNext();) { //String cityName = ( String )new String( iter.next().toString() ); String cityName = ( String ) new String( iter.next().toString() ); out.println("<p>"+ cityName +"</p>"); }*/ out.println("</body>"); out.println("</html>"); out.close(); }
Any suggestions? :)
Thankz :) -
5. Re: Help on java.lang.ClassCastException: java.lang.String
jaikiran Oct 19, 2006 6:57 AM (in response to scout1lacno)Are you sure you changed the code at the right place. Your first post had the following code, which i asked you to change:
TblCountryFacadeLocal myCountryBean = lookupTblCountryFacade(); List myList = myCountryBean.findAll(); int length = myList.size(); for (int i = 0; i < length; i++) { TblCSCSubCategory region = (TblCSCSubCategory) myList.get(i) ; System.out.println((i + 1)+". "+region.getStrName().toString()); }
The code that you changed has something different:TblCountryFacadeLocal myCountryBean = lookupTblCountryFacade(); List myList = myCountryBean.findAllCat(); int length = myList.size(); for (int i = 0; i < length; i++) { //TblCountry region = (TblCountry) myList.get(i) ; String country = (String) myList.get(i); System.out.println(country); }