post your comment   print   send to a friend
Rate:   0% | Views: 603
Question categories:  Java

Why do I get a Javascript error using a String returned from a Java Applet to index an array?

 You might get the error: IncompatibleClassChangeError java.lang.String:?

A Java String returned to JavaScript is wrapped by a JavaScript method object. When this object is used in an expression requiring a string, the wrapper's toString() method is called and a JavaScript String is returned. Since Array indexing is an implied polymorphic method (integer index or string property name), the toString() method is not called and the indexing method fails with this error. 4.0 handles this however. [4.0]

A simple workaround in 3.x is to force the conversion to a string.

For example:


var fred = myAppLet.spouse("wilma")
myDoc.myForm.elements[fred ].clicke// this yields the error
myDoc.myForm.elements[""+fred].clicke

Customer Feedback
Rate:   0% | Views: 603 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Domain Name Registration | Increase Website Traffic    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Do It Yourself
    Java
Messages
 

Blogging at Aplus.Net

Don't forget to check out our blog ! Keep up to date at Aplus.Net.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. How do I access Servlets or CGI programs from Java?
 
2. My applet computes its window size. Can I resize it in the browser?
 
3. How do I communicate between my applets in the same browser?
 
4. How do I force the browser to reload my Java classes without exiting Navigator?
 
5. Why does my java console show an applet is pruned?
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest