Friday, April 2, 2010

perty or method of a null object...

I suppose it's cheezy to offer money for some help (and I suppose this somewhat related to a post being discussed yesterday), but I'm so tired of looking at this - been trying things ALL day and its worth at a minimum 50 bucks if someone takes some time to help with an explanation of what's going on and how to fix it?(hopefully it's just some newbie issue that I'll be cursing myself for missing.)

I have things stripped down to a narrow version of the application to demonstrate the problem. You can download it (link at bottom of page) and just run the html/swf in bin-debug and you'll see the problem (or maybe figure it out from the code linke provided also.) Click login and then 'add employee' and just put the cursor in the firstname text field and click. You'll end up with the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
?at mx.managers::FocusManager/focusInHandler()[C:\autobuild\galaga\frameworks\proje cts\framework\src\mx\managers\FocusManager.as:601]
?at flash.display::Stage/set focus()
?at mx.core::UITextField/setFocus()[C:\autobuild\galaga\frameworks\projects\framewo rk\src\mx\core\UITextField.as:1525]
?at mx.controls::TextInput/setFocus()[C:\autobuild\galaga\frameworks\projects\frame work\src\mx\controls\TextInput.as:1832]
?at mx.managers::FocusManager/setFocus()[C:\autobuild\galaga\frameworks\projects\fr amework\src\mx\managers\FocusManager.as:553]
?at mx.managers::FocusManager/mouseDownHandler()[C:\autobuild\galaga\frameworks\pro jects\framework\src\mx\managers\FocusManager.as:1896]

I know the problem is related to _defaultButton being null in focusInHandler of FocusManager (at least the debugger shows the problem here), but not sure why it's ******** there. You'll see in both simple view stacks I've set creationPolicy=''all'' (I even tried setting createionPolicy=''all'' on almost all the components.)

View the main pertinent files:

http://pastie.org/610389

Download the sample app demonstrating the issue

http://dl.getdropbox.com/u/86998/EmployeeMaintenanceTest.zip

perty or method of a null object...

First word was ''Property'' - got cut off:)

perty or method of a null object...

That's a bug. I think the workaround is to set defaultButton on the main app.

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

How exatctly do I set the defaultButton from the main page?

I tried:

//on main component

var but:Button = new Button();
but.label = ''BOO'';

empForm.dButton = but;


//and on employeForm component

[Bindable] public var dButton:Button;

%26lt;mx:Form id=''empForm'' defaultButton=''{dButton}''%26gt;

The above didn't help at all (same error).

Assuming I do have to create it like above somehow, I'm also currious , do I also need to add my click handler to the button in my main form where I'm setting the default button?

Sorry for the confusion.

I'm also wondering if I'm doing something wrong since when I google about this, I find little about it, so it makes me think the problem isn't common which leads me to believe I'm setting up my application wrong?

I have two view stacks (one component on parent view stack has another view stack as part of its component) and one of the components in the secons viewstack is a form. When this form is brought up, the error occurs. How come others not running into this same issue quite frequently?

I've even tried this which I also don't understand why it doesn't work. I'll see the init called when the app is launch so no clue why it keep complaing about the defaultButton

in my EmployeeForm.xml

..... creationComplete=''init()''%26gt;

private function init():void {
?empForm.defaultButton = submitButton;?
?Alert.show(''init called'');
}

%26lt;mx:Form id=''empForm''?%26gt;

%26lt;mx:Button id=''submitButton'' click=''submitEmployee()'' label=''submit''/%26gt;

No luck:( ... and the frustration continues.

On a positive note, I decided to try flex4 and I'm not getting the error in flex4. Is a fix going to be released in flex3?

If you file a bug with your testcase, it'll help ensure that we don't break this in Flex 4. I don't know if there will be another 3.x release.

I got around your problem by adding to top-level Canvas in Main.mxml:

defaultButton=''{mainNavigation.addEmployeeButton}''

I believe the principle is that once you assign a default button in one container, you have to keep something as the default button after that. If focus goes to a container without a default button, then I think there's trouble.

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

Thought I'd chime in on this since I just overcame this issue myself.?Using the Flex 3.4 SDK, btw.

I'm working on an AIR app that uses a ViewStack to navigate through a what is essentially and application start up wizard: the app starts up, the user logs in and then decides what to do.?Each of these things (and more) is represented by a Form that is a child of the ViewStack.?One of these forms has a button defined for it's defaultButton property but the form before it does not.?Apparently this was the source of my error as defining a defaultButton for the earlier form cleared up the issue.

The really odd thing about this is that I did not have this problem until today, and this form has been in place for months.

It is new in 3.4. https://bugs.adobe.com/jira/browse/SDK-21780

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

It's not really a problem for me as the work around is fine in my case.

I'm curious though, I switched to 3.4 a couple of weeks ago now and it just showed up as a runtime error yesterday.?The only thing I can think is that I hadn't opened the actual file that caused the error since switching from 3.3 to 3.4.?Would Flex Builder not re-compile the MXML component in question since it had not been edited??Put another way, why would this only show up now and not as soon as I switched SDK versions?

Thanks.

No comments:

Post a Comment