New topic: illegalCastException [solved]
<http://forums.realsoftware.com/viewtopic.php?t=30559> Page 1 of 1 [ 12 posts ] Previous topic | Next topic Author Message AaronAndrewHunt Post subject: illegalCastException [solved]Posted: Mon Oct 19, 2009 9:04 pm Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 Today I updated to RB2009r4 and am converting my projects from 2007r5. I had some headaches from the nonsense because of the Editfield deprication, but was able to solve that in all my applications; however, one application is giving me an illegalCastException error whenever I refer to a particular window in the app. By referring I mean: theWindow.whatever written as code in some other window. Calling a method or reading a property, whatever. It brings up this bloody error. I can't find the source of this error, or get rid of this error. I can find absolutely no reason for it. Never saw such an error before. Searching on here brought up examples where arrays were previously created with EditFields which RB changed some of the controls to TextEdit and some to TextArea, and the soltution is to change them all either to one or the other. So I looked for any such arrays in this app. None. So then I thought maybe this is happening because I have a method and a property by the same name. Looked for that. Lots of fun. Pick a word and see if you can find it in two places! Yippee! What a way to spend your day... I don't even know if that is something that would cause this error. So, at wits end as usual, I thought I'd ask here. Thank you kindly for any help you can offer. Yours, Aaron ===== http://www.h-pi.com Last edited by AaronAndrewHunt on Tue Oct 20, 2009 1:16 am, edited 1 time in total. Top Phil M Post subject: Re: illegalCastExceptionPosted: Mon Oct 19, 2009 10:29 pm Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 RB Language Reference wrote:An IllegalCastException error occurs when you attempt to cast an object to a different type and call a method or access a property belonging only to the original type. Yeah there are a lot of funny thing going on with the TextField and TextArea transition. Are you able to display the error when you run in the debugger? It should stop at or near the line where the error occurred. Of course if you run Plugins or encrypted RB code, it might be the error happened in there, and REALbasic is unable to point exactly where. If the debugger isn't showing you enough info on where the problem is appearing, you might have to invest some time with Introspection and trying to track down the problem that way. Top AaronAndrewHunt Post subject: Re: illegalCastExceptionPosted: Mon Oct 19, 2009 10:48 pm Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 The error is shown in the debugger at whatever line of code refers to something in this window. If I comment out the line that's causing the exception, the exception will be thrown somewhere else that is referring to the window. It's as if this window in and of itself is a poison, causing this exception anywhere it is referred to. I've looked at everything in the window, all its objects (which are not many) and can't see anything wrong. There are 6 Bevelbuttons, a slider and a TextArea. I've head mention of this "Introspection" you speak of, but have no idea what you mean about spending time with that. Thanks, Aaron Top Phil M Post subject: Re: illegalCastExceptionPosted: Tue Oct 20, 2009 12:21 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 AaronAndrewHunt wrote:The error is shown in the debugger at whatever line of code refers to something in this window. If I comment out the line that's causing the exception, the exception will be thrown somewhere else that is referring to the window. It's as if this window in and of itself is a poison, causing this exception anywhere it is referred to. I've looked at everything in the window, all its objects (which are not many) and can't see anything wrong. There are 6 Bevelbuttons, a slider and a TextArea. Well if its just the window, maybe the code defining it has gotten corrupt. Try exporting it as an XML item, delete the regular version from your document, and then reimport the XML. Quote:I've head mention of this "Introspection" you speak of, but have no idea what you mean about spending time with that. It can help you determine properties and methods of mostly unknown classes etc. Based on what you said in paragraph above, its not likely that introspection can help. Top Phil M Post subject: Re: illegalCastExceptionPosted: Tue Oct 20, 2009 12:23 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 Oh another thing... you DON'T have to make your TextArea and TextFields into Editfields. Reopen your original RB2007 document and when it asks you to resolve, just ignore it (of course you have to do that every time you open the project). But at least as a test... see if your app still generates that exception. Top AaronAndrewHunt Post subject: Re: illegalCastExceptionPosted: Tue Oct 20, 2009 12:45 am Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 I saved the project as xml and opened it. No change. If I don't resolve the EditFields into TextFields and TextAreas, there are exceptions thrown all over the place. EditField is no longer recognized... The method I used to get rid of EditFields completely and resolve any problems was: - click resolve for all at load - search and replace all EditField replace with TextArea - search and replace all TextEdit with TextArea - I found that methods and properties using EditField may have to be changed manually If a method previously had an editfield passed to it, it will now be broken if it now is passed a TextEdit. I changed everything to TextArea since it is the new class that allows both for single and multi line input like EditField. Is there really NO CLASS to stand for both TextEdit and TextArea? I can't find one. If there is no class to stand for both of these, RB staff, this deprication is extremely annoying and a real step backwards, no matter if it corresponds better to the Apple API. You broke perfectly good code, made an object *less useful*, and made 2 new objects that are less versatile. Broken methods previously using EditField are now unavoidable when the field passed could either be taken from what has now been renamed a TextArea or from a listbox activecell, which is now a TextEdit. In that case, you have to copy the TextEdit activeCell properties to a TextArea, and pass any other needed properties (can be done using the 'optional' keyward in the receiving method), then copy the textArea back to the textEdit after the method has been called. I had subclassed all kind of custom EditFields for various purposes, multi and single line, which could be passed to methods along with listbox cells. Now that does not work without this ridiculous workaround. Very, very annoying. Enough venting. What I really need is to find what is causing this illegalCastException and fix it. Any other ideas? Thanks, Aaron Top AaronAndrewHunt Post subject: Re: illegalCastExceptionPosted: Tue Oct 20, 2009 1:11 am Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 Good news - I found it and fixed it. It was in fact a case of using the same name for a custom subclassed object (in the Project pane) and the name of an object in that window. This made any reference to that window throw an illegalCastException. I changed the name of the custom class along with any references to it, and everything is fine now. I could have changed the name of the object in the window, but didn't want to do that to keep the code reading the same as it had been before. The only reason I found this is because of your advice to export xml. I decided to export just that window as an xml, and open it as a new file to see if that window would run on its own without throwing the exception. It popped up with that custom class not existing, which led me to the solution. Thanks very much for the help, as always. I love this forum. Cheers, Aaron P.S. And of course the guys at RB dev are the best. They tend to hear all the venting and little praise. RB is great and I love programming with it. Great product and great support, I recommend it highly. Thanks and keep it up. Last edited by AaronAndrewHunt on Tue Oct 20, 2009 1:19 am, edited 1 time in total. Top Phil M Post subject: Re: illegalCastExceptionPosted: Tue Oct 20, 2009 1:19 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 AaronAndrewHunt wrote:It was in fact a case of using the same name for a custom object and an object in that window. I had subclassed a timer with a name that I used for an object in that window. This made any reference to that window throw an illegalCastException. I changed the name of the custom class along with any references to it, and everything is fine now. Compiler should have caught that... the fact that it didn't is probably a bug. Feel like throwing out everything except that object in the window and the timer subclass and submit a bug report for it? Top AaronAndrewHunt Post subject: Re: illegalCastException [solved]Posted: Tue Oct 20, 2009 1:22 am Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 Well, it did catch it, but in a weird way, and not in a way that allowed me see what it was catching exactly, so I could not fix it easily. What should have been the exception, and how should it have looked? It seems this has happened to me before, but it did not throw this illegalCastException exception. It gave some other error. Aaron Top Phil M Post subject: Re: illegalCastException [solved]Posted: Tue Oct 20, 2009 1:35 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 AaronAndrewHunt wrote:Well, it did catch it, but in a weird way, and not in a way that allowed me see what it was catching exactly, so I could not fix it easily. What should have been the exception, and how should it have looked? It seems this has happened to me before, but it did not throw this illegalCastException exception. It gave some other error. Should have been a compiler error showing up on the Bug Tab (app failed to compile) with a message something like "this name is already in use" or "cannot have a control with the same name as a class". Although I think your situation was a bit more complicated because I tried to reproduce the bug as you described it and I cannot get it to break for me. If your control was named exactly the same its class name then that is just weird, because the IDE does not allow me to make the names for an instance of a class to be the same as the class. Top AaronAndrewHunt Post subject: Re: illegalCastException [solved]Posted: Tue Oct 20, 2009 1:41 am Joined: Sat Jul 14, 2007 2:16 pm Posts: 166 I also cannot get it to break. This is very weird. The project is: - main window named: MainWindow (parent window, contains no code) - custom object named: CustomTimer (subclass of Timer, contains no code) - custom object named: CustomThread (subclass of Thread, contains one property, custTime as CustomTimer) In the main window, place a CustomThread object there and name it CustomTimer The debugger sees nothing wrong with this? I added another window called Window1 with this code in its Open Event: Code: dim j as integer = MainWindow.CustomTimer.State Still nothing. I added a BevelButton to MainWindow and added this code to the Open event of Window1. Code: MainWindow.BevelButton1.addrow "test" Though this would seem to replicate the situation I had in the actual app, referring to something in the window that has this custom class name / object name conflict, still nothing is shown in the debugger. Hmm. I don't know why the debugger sees nothing wrong with this in this little test app ... *and yet* threw the illegalCastException in my actual app... Should this be filed as a bug report? The debugger does nothing in one case and something weird in another, with no clear explanation for either behavior. Thanks, Aaron Top Phil M Post subject: Re: illegalCastException [solved]Posted: Tue Oct 20, 2009 2:32 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 159 That XML file that you exported your window as, when you import it to a new project including your custom class(es) that are in question, does it still break? If yes, can you submit that as the bug report? But if that doesn't break, then I guess there really is not much you can do other than blame it on bad luck. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 12 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
