Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 466 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Cannot cast from ActionForm to StudentForm

807603
Member Posts: 44,391
Hi All,
I am getting this Eroor
Cannot cast from ActionForm to StudentForm
Thanks
AS
I am getting this Eroor
Cannot cast from ActionForm to StudentForm
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { StudentService service = new StudentService(); StudentForm studentForm = (StudentForm) form; //Error is shown here... StudentDTO studentDTO = new StudentDTO(); BeanUtils.copyProperties( studentDTO, studentForm ); service.insertStudent( studentDTO ); request.setAttribute("employee",studentDTO); return (mapping.findForward("success")); }Any help would be greatly appreciated.
Thanks
AS
Comments
-
Ok, so form must not be a StudentForm object. Just like you can't do this:
Object o = new Object();
String s = (String) o;
What made you think that the object passed to that method really is a StudentForm object? -
Ok, so form must not be a StudentForm object. JustThanks for the reply.I dont quite understand what u mean .........
like you can't do this:
Object o = new Object();
String s = (String) o;
What made you think that the object passed to that
method really is a StudentForm object?
hopefully u explain in more detail
AS -
Are you under the impression that you can just cast from any object type to another? You can't. So unless the actual object type passed to that method really is a StudentForm object (or a subclass of StudentForm), you can't just willy-nilly cast it and expect it to work.
-
Are you under the impression that you can just castThanks for the reply again
from any object type to another? You can't. So unless
the actual object type passed to that method really
is a StudentForm object (or a subclass of
StudentForm), you can't just willy-nilly cast it and
expect it to work.
I think i am getting what u r saying here....
StudentForm is a subclass of Action, so i guess it is the actual object type StudentForm, let me know whether i am right with this, and dont be harsh
Thanks
AS -
StudentForm is a subclass of Action, so i guess it isJust because StudentForm is a subclass of Action doesn't mean the actual object passed is a StudentForm.
the actual object type StudentForm, let me know
whether i am right with this, and dont be harsh
class Action { ... }
class StudentForm extends Action { ... }
Action x = new Action();
StudentForm y = (StudentForm) x; // can't do this - you (or whatever on your behalf) didn't actually create a StudentForm object.
If you want to see what was actually passed to that method, do this:
System.out.println("form is a: " + form.getClass());
before that line where you're trying to cast it. Then examine the output and you'll see what kind of object was actually passed in. -
(and you must have meant ActionForm, not Action - so adjust my reply accordingly)
This discussion has been closed.