Foros de discusión

class cast exception help

thumbnail
ganesh sahu, modificado hace 11 años.

class cast exception help

Junior Member Mensajes: 73 Fecha de incorporación: 24/07/12 Mensajes recientes
i have created a studentFinderImpl class which uses the custom sql to return a List object.I am using the search container to show the results but its giving a class cast exception saying object can not be casted to app.model.student.

i am giving my code please have a look

studentFinderImpl class

public class studentFinderImpl extends BasePersistenceImpl<student> implements studentFinder
{

	public List<student> findStudents() throws SystemException
	{
		System.out.println("invoked inside findstudents");
		SQLQuery query2=null;
		Session session = null;
		try {	
		
		final String id1="findstudents";
		session = openSession();
		String sql = CustomSQLUtil.get(id1);
		SQLQuery query = session.createSQLQuery(sql);
		query2=query;
		//query.addEntity(“student”,studentImpl.class);
		//QueryPos qPos = QueryPos.getInstance(query);
		//qPos.add(name);
		
		
		}
		
		catch(Exception e)
		{
			}
		
		
		
		return(List) query2.list();
		
		}
		
		
		
		
		
		
		
		}
		

</student></student>


studentlocalserviceimpl class


public class studentLocalServiceImpl extends studentLocalServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link com.app.lop.service.studentLocalServiceUtil} to access the student local service.
	 */
	
	
public List getmystudents()
	{
	List<student> a=null;
	
	try {
		a=studentFinderUtil.findStudents();
		

		
		
		
		
	} catch (com.liferay.portal.SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}	
    	
 
		
	return a;
		
	}
	
}

</student>


in result.jsp


&lt;%@page import="java.util.Iterator"%&gt;
&lt;%@page import="java.util.ArrayList"%&gt;
&lt;%@page import="com.app.lop.model.student"%&gt;
&lt;%@page import="java.util.List"%&gt;
&lt;%@page import="javax.portlet.*,com.liferay.portal.kernel.util.ListUtil"%&gt;
&lt;%@page import="com.app.lop.service.studentLocalServiceUtil"%&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %&gt;
<portlet:defineobjects />

&lt;%


List<student> a=(List)studentLocalServiceUtil.getmystudents();


int count=studentLocalServiceUtil.getstudentsCount();

PortletURL iteratorURL = renderResponse.createRenderURL();


%&gt;


<liferay-ui:search-container delta="4" emptyresultsmessage="no such user" iteratorurl="<%=iteratorURL%>">


    <liferay-ui:search-container-results>
    &lt;%
    results= ListUtil.subList(a,searchContainer.getStart(),searchContainer.getEnd());

    total=a.size();
    
    System.out.println("inside this jsp");
    
    pageContext.setAttribute("results",results);
    pageContext.setAttribute("total",total);

    %&gt;
    
          </liferay-ui:search-container-results>
    
  
       

    <liferay-ui:search-container-row classname="com.app.lop.model.student" keyproperty="studentid" modelvar="data">
        <liferay-ui:search-container-column-text name="fname" property="studentname" />

        <liferay-ui:search-container-column-text name="mycity" property="city" />
         
          <liferay-ui:search-container-column-text name="college" property="college" />
        
        <liferay-ui:search-container-column-jsp path="/html/data/edit.jsp">
        </liferay-ui:search-container-column-jsp>
        

        
    </liferay-ui:search-container-row>
    

    <liferay-ui:search-iterator searchContainer="<%= searchContainer %>" paginate="true" />
    
</liferay-ui:search-container>


</student>
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: class cast exception help

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
You didn't post the error message. In which file and which row is the error occurring?
thumbnail
ganesh sahu, modificado hace 11 años.

RE: class cast exception help

Junior Member Mensajes: 73 Fecha de incorporación: 24/07/12 Mensajes recientes
the error is in result.jsp saying ------------------------------>Object can not be casted to com.app.lop.model.student

<liferay-ui:search-container-row
className="com.app.lop.model.student"
keyProperty="studentid"
modelVar="data"
>
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: class cast exception help

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Before the search tag, try looping through the result from the finder method to see if "studentid" and other columns are being returned.
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: class cast exception help

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
You have commented this line:
//query.addEntity(“student”,studentImpl.class);
try uncommenting this line
and also at the end you are writing:
return(List) query2.list();

instead of
return(List<student>) query2.list();</student>
Umasankar Jeyaraj, modificado hace 10 años.

RE: class cast exception help

New Member Mensajes: 7 Fecha de incorporación: 16/07/13 Mensajes recientes
Aryan sahu:
the error is in result.jsp saying ------------------------------>Object can not be casted to com.app.lop.model.student

<liferay-ui:search-container-row
className="com.app.lop.model.student"
keyProperty="studentid"
modelVar="data"
>



Hi Aryan,
I am getting the same issue. Did you get any solution for this???
thumbnail
Christoph Rabel, modificado hace 10 años.

RE: class cast exception help

Liferay Legend Mensajes: 1554 Fecha de incorporación: 24/09/09 Mensajes recientes
Take a look at the answer of Prakash Khanchandani. If this doesn't help you, please post some code (especially the finder implementation).