0

ERROR : java.lang.ClassCastException:

asked 2009-10-14 13:50:41 +0800

cros gravatar image cros
153

I have following code in zul file ====

def abc='HOSPITAL'
alert("abc="+abc);
def c1=ClientMap.executeQuery('select id from ClientMap where name=?',)
alert("c1="+c1)

This works fine. ALert displayes value as abc=HOSPITAL & c1=[1]

But when i pass value at runtime as==

def abc=item.value
alert("abc:="+abc)
def c1=ClientMap.executeQuery('select id from ClientMap where name=?',)
alert(c1)

Alert displayes value as abc=HOSPITAL & throws an error for c1 as
"java.lang.ClassCastException: org.zkoss.zul.SimpleTreeNode cannot be cast to java.lang.String"

Can any body HELP ME ?????

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-10-14 14:36:45 +0800

cros gravatar image cros
153

I'll be thankful to you if u come up with the solution.

link publish delete flag offensive edit

answered 2009-10-15 10:53:31 +0800

iantsai gravatar image iantsai
2755 1

alert's argument can only accept String, I think that's the reason.

link publish delete flag offensive edit

answered 2009-10-15 12:54:19 +0800

cros gravatar image cros
153

Thanx Iantsai for ur reply.... I passed the value as a string and tried ,but still facing the same problem.

link publish delete flag offensive edit

answered 2009-10-27 22:49:00 +0800

iantsai gravatar image iantsai
2755 1

Then, what's your new code and error?

link publish delete flag offensive edit

answered 2021-07-12 13:15:46 +0800

kevinkatler gravatar image kevinkatler
1

The exaception thrown to indicate that your code has attempted to cast an object to a subclass of which it is not an instance. This means that ClassCastException occurs when you try to cast an instance of an Object to a type that it is not. Type Casting only works when the casted object follows an is a relationship to the type you are trying to cast to.

It is good practice to guard any explicit casts with an instanceof check first:

if (myApple instanceof Fruit) { Fruit myFruit = (Fruit)myApple; }

When will be ClassCastException is thrown:

When you try to cast an object of Parent class to its Child class type, this exception will be thrown.

When you try to cast an object of one class into another class type that has not extended the other class or they don't have any relationship between them.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-14 13:50:41 +0800

Seen: 398 times

Last updated: Jul 12 '21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More