[flexcoders] Cannot access a property or method of a null object reference at mx.controls::Tree/::buildUpCollectionEvents()
Hi All! When I add a new item to the tree node and then open this item by user input null pointer exceptions is thrown and after that Tree behavior becomes strange. Steps to reproduce: 1. Run application. 2. Select My Branch node. 3. Click Add button. As a result My Leaf subnode is created as a child of My Branch. 4. Click My Leaf disclosure icon to expland this item. 5. Exception mentioned above is thrown. I compile this example in Flex 2.01 and run in Flash Player 9.0.47.0. We have found workaround. The bug can be fixed by setting Tree openDuration style to 0. But I dislike workarounds. Are there any real solutions to fix this bug? Sergey. ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical mx:Script ![CDATA[ *import* mx.collections.XMLListCollection; *private* *static* *const* itemsXML : XML = root item label=*My Branch* isBranch=*true* / /root; *private* *static* *const* itemsXMLListCollection : XMLListCollection = *new* XMLListCollection(itemsXML.children()); *private* *function* onAddButtonClick() : *void* { *var* parentXML : XML = XML(tree.selectedItem); *var* newItemXML : XML = item label=*My Leaf* isBranch=*true* /; tree.dataDescriptor.addChildAt(parentXML, newItemXML, parentXML.length()); } ]] /mx:Script mx:Tree id=tree labelField=@label showRoot=false dataProvider={itemsXMLListCollection} / mx:Button label=Add click=onAddButtonClick() / /mx:Application
[flexcoders] Cannot access a property or method of a null object reference?
Hi I'my working whit flex and amfphp. In my exercise, the flex debug say this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at cys/changeHandler()[D:\My Documents\FlexBuilder3\cys\src\cys.mxml:51] at cys/__atclass_close()[D:\My Documents\FlexBuilder3\cys\src\cys.mxml:70] line around 51: public function changeHandler(event:Event):void { var atClass:Object = new Object; atClass.atcls = ComboBox(event.target).selectedItem.data; gateway.call(Cys.getStudents, new Responder(getResult, onFault), atClass); // this is line 51 } getResult is another function that give the result to ComboBox's dataProvider: public function getResult(result:Array):void { ssProvider = result; } onFault: public function onFault(fault:String ):void { trace(fault); } line 70: mx:ComboBox y=202 id=atclass close=changeHandler(event); dataProvider={atClassProvider} fontSize=12 x=40/mx:ComboBox this comboBox can display properly. Cys is a Class, it is under amfphp/services and its file code: ?php Define('DATABASE_SERVER', 'localhost'); Define('DATABASE_USERNAME', 'root'); Define('DATABASE_PASSWORD', '123456'); Define('DATABASE_NAME', 'cys'); class Cys { var $mysqli; function Cys() { # Connect to MySQL database $this-mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME); # Check MySQL connection if (mysqli_connect_errno()) { # Dont use die (Fatal Error), return useful info to the client trigger_error(AMFPHP Remoting class could not connect: . mysqli_connect_error()); } } function getStudents($atClass) { # Return a list of all the users $atcls = $this-mysqli-real_escape_string(trim($atClass['atcls'])); $sql = SELECT * from students where atclass = '.$atcls.'; if ([EMAIL PROTECTED]mysqli-query($sql)) { $errno=$this-mysqli-errno; $this-mysqli-close(); trigger_error(AMFPHP Remoting class database SELECT query error: . $errno); } while ($row = $result-fetch_assoc()) { $user_array[] = $row; } return($user_array); } } ?
Re: [flexcoders] Cannot access a property or method of a null object reference?
Hi, From the look if it ;ComboBox(event.target).selectedItem seems to be where the null pointer is. Make sure you actually have a selectedItem in the list. I have actually done this myself when testing and actually forgot to 'select' an item before a service call. Mike On Mon, Jun 9, 2008 at 6:52 AM, xaero [EMAIL PROTECTED] wrote: Hi I'my working whit flex and amfphp. In my exercise, the flex debug say this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at cys/changeHandler()[D:\My Documents\FlexBuilder3\cys\src\cys.mxml:51] at cys/__atclass_close()[D:\My Documents\FlexBuilder3\cys\src\cys.mxml:70] line around 51: public function changeHandler(event:Event):void { var atClass:Object = new Object; atClass.atcls = ComboBox(event.target).selectedItem.data; gateway.call(Cys.getStudents, new Responder(getResult, onFault), atClass); // this is line 51 } getResult is another function that give the result to ComboBox's dataProvider: public function getResult(result:Array):void { ssProvider = result; } onFault: public function onFault(fault:String ):void { trace(fault); } line 70: mx:ComboBox y=202 id=atclass close=changeHandler(event); dataProvider={atClassProvider} fontSize=12 x=40/mx:ComboBox this comboBox can display properly. Cys is a Class, it is under amfphp/services and its file code: ?php Define('DATABASE_SERVER', 'localhost'); Define('DATABASE_USERNAME', 'root'); Define('DATABASE_PASSWORD', '123456'); Define('DATABASE_NAME', 'cys'); class Cys { var $mysqli; function Cys() { # Connect to MySQL database $this-mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME); # Check MySQL connection if (mysqli_connect_errno()) { # Dont use die (Fatal Error), return useful info to the client trigger_error(AMFPHP Remoting class could not connect: . mysqli_connect_error()); } } function getStudents($atClass) { # Return a list of all the users $atcls = $this-mysqli-real_escape_string(trim($atClass['atcls'])); $sql = SELECT * from students where atclass = '.$atcls.'; if ([EMAIL PROTECTED]mysqli-query($sql)) { $errno=$this-mysqli-errno; $this-mysqli-close(); trigger_error(AMFPHP Remoting class database SELECT query error: . $errno); } while ($row = $result-fetch_assoc()) { $user_array[] = $row; } return($user_array); } } ? -- Teoti Graphix, LLC http://www.teotigraphix.com Teoti Graphix Blog http://www.blog.teotigraphix.com You can find more by solving the problem then by 'asking the question'.
RE: [flexcoders] Cannot access a property or method of a null object reference
That's because when you simply declare var test:testClass; the variable 'test' is automatically assigned a default value of null. The default value of a var depends on its type, as follows: Boolean -- false int/uint -- 0 Number -- NaN Object -- undefined All other types -- null Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Christophe Herreman Sent: Tuesday, January 01, 2008 12:15 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Cannot access a property or method of a null object reference Hi, you need to create an instance of the testClass like this var test:testClass = new testClass(); regards, Christophe -- Christophe Herreman http://www.herrodius.com http://www.herrodius.com http://www.pranaframework.com http://www.pranaframework.com 2008/1/1, [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] : This compiles but when you hit the test button, it says TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/test() at Main/__b1_click() Can anyone explain what this means ? It totally does not make any sense to me. main.mxml: ?xml version=1.0? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml mx:Script source=MainCode.as/ mx:Button id=b1 label=Test click=test();/ /mx:Application MainCode.as: Public function test():void { var test:testClass; test.justtesting(); } testClass.as: package { public class testClass { public function testClass() { } public function justtesting():void { trace(just testing); } } } -- Christophe Herreman http://www.herrodius.com http://www.herrodius.com http://www.pranaframework.org http://www.pranaframework.org
[flexcoders] Cannot access a property or method of a null object reference
This compiles but when you hit the test button, it says TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/test() at Main/__b1_click() Can anyone explain what this means ? It totally does not make any sense to me. main.mxml: ?xml version=1.0? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; mx:Script source=MainCode.as/ mx:Button id=b1 label=Test click=test();/ /mx:Application MainCode.as: Public function test():void { var test:testClass; test.justtesting(); } testClass.as: package { public class testClass { public function testClass() { } public function justtesting():void { trace(just testing); } } }
Re: [flexcoders] Cannot access a property or method of a null object reference
Hi, you need to create an instance of the testClass like this var test:testClass = new testClass(); regards, Christophe -- Christophe Herreman http://www.herrodius.com http://www.pranaframework.com 2008/1/1, [EMAIL PROTECTED] [EMAIL PROTECTED]: This compiles but when you hit the test button, it says TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/test() at Main/__b1_click() Can anyone explain what this means ? It totally does not make any sense to me. main.mxml: ?xml version=1.0? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; mx:Script source=MainCode.as/ mx:Button id=b1 label=Test click=test();/ /mx:Application MainCode.as: Public function test():void { var test:testClass; test.justtesting(); } testClass.as: package { public class testClass { public function testClass() { } public function justtesting():void { trace(just testing); } } } -- Christophe Herreman http://www.herrodius.com http://www.pranaframework.org
Re: [flexcoders] Cannot access a property or method of a null object reference
Thanks, that was it. Christophe Herreman wrote: Hi, you need to create an instance of the testClass like this var test:testClass = new testClass(); regards, Christophe -- Christophe Herreman http://www.herrodius.com http://www.herrodius.com http://www.pranaframework.com http://www.pranaframework.com 2008/1/1, [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]: This compiles but when you hit the test button, it says TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/test() at Main/__b1_click() Can anyone explain what this means ? It totally does not make any sense to me. main.mxml: ?xml version=1.0? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml mx:Script source=MainCode.as/ mx:Button id=b1 label=Test click=test();/ /mx:Application MainCode.as: Public function test():void { var test:testClass; test.justtesting(); } testClass.as: package { public class testClass { public function testClass() { } public function justtesting():void { trace(just testing); } } } -- Christophe Herreman http://www.herrodius.com http://www.herrodius.com http://www.pranaframework.org http://www.pranaframework.org
Re: [flexcoders] Cannot access a property or method of a null object reference
you forgot to instantiate the object. Change: var test:testClass; to var test:testClass = new testClass(); and it should work. Regards, Frederico Garcia On Tue, 01 Jan 2008 14:45:00 -0500, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: This compiles but when you hit the test button, it says TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/test() at Main/__b1_click() Can anyone explain what this means ? It totally does not make any sense to me. main.mxml: ?xml version=1.0? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; mx:Script source=MainCode.as/ mx:Button id=b1 label=Test click=test();/ /mx:Application MainCode.as: Public function test():void { var test:testClass; test.justtesting(); } testClass.as: package { public class testClass { public function testClass() { } public function justtesting():void { trace(just testing); } } } -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links
[flexcoders] Cannot access a property or method of a null object reference
I often get this error and I usually know why. Does anyone know how to check for a null reference? i.e. if (dataprovider[i].someValue is null){ dothis(); } Where dataprovider[i] does not have a someValue property. I bet this is pretty simple and I just don't know the syntax. Thanks in advance!
RE: [flexcoders] Cannot access a property or method of a null object reference
I bet that is correct. I have found that it is best to use callLater for any control manipulation if I have just modified the dataProvider. But, Roger, don't guess. Debug the code to find out which line is producing the error. If you don't have good debugging techniques, develop them now. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Clint Tredway Sent: Thursday, January 25, 2007 12:07 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Cannot access a property or method of a null object reference most likely the setting of the selectedIndex is what is causing that error. Its trying to set a property to a component that doesnt exist yet. On 1/25/07, Roger Ross [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello, Working my way throught the Training From the Source turorial and ran into this error message. Not sure why I am getting it. I compared my code to the completed code for the lesson and it looks the same with no problems when I compile it. TypeError: Error #1009: Cannot access a property or method of a null object reference. at Dashboard/::catHandler() at Dashboard/__catRPC_result() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEven tFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal ::dispatchRpcEvent http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent () at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resu ltHandler http://www.adobe.com/2006/flex/mx/internal::resultHandler () at mx.rpc::Responder/result() at mx.rpc::AsyncRequest/acknowledge() at ::DirectHTTPMessageResponder/completeHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEven tFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete() Here is a copy of the code that it has me write with the comboBox that is to receive the data: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml layout=horizontal creationComplete=catRPC.send() mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var categories:ArrayCollection=new ArrayCollection(); private function catHandler(event:ResultEvent):void{ categories = event.result.catelog.category; var catObj:Object = new Object(); catObj.name = All; catObj.categoryID = 0; categories.addItemAt(catObj, 0); catCombo.selectedIndex = 0; } ]] /mx:Script mx:HTTPService id=catRPC url=http://www.flexgrocer.com/category.xml http://www.flexgrocer.com/category.xml result=catHandler(event)/ mx:ComboBox id=catCombo dataProvider={categories} labelField=name/ Any Idea's... Thanks, Roger -- http://indeegrumpee.spaces.live.com/ http://indeegrumpee.spaces.live.com/
[flexcoders] Cannot access a property or method of a null object reference
Hello, Working my way throught the Training From the Source turorial and ran into this error message. Not sure why I am getting it. I compared my code to the completed code for the lesson and it looks the same with no problems when I compile it. TypeError: Error #1009: Cannot access a property or method of a null object reference. at Dashboard/::catHandler() at Dashboard/__catRPC_result() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent() at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler() at mx.rpc::Responder/result() at mx.rpc::AsyncRequest/acknowledge() at ::DirectHTTPMessageResponder/completeHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete() Here is a copy of the code that it has me write with the comboBox that is to receive the data: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=horizontal creationComplete=catRPC.send() mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var categories:ArrayCollection=new ArrayCollection(); private function catHandler(event:ResultEvent):void{ categories = event.result.catelog.category; var catObj:Object = new Object(); catObj.name = All; catObj.categoryID = 0; categories.addItemAt(catObj, 0); catCombo.selectedIndex = 0; } ]] /mx:Script mx:HTTPService id=catRPC url=http://www.flexgrocer.com/category.xml; result=catHandler(event)/ mx:ComboBox id=catCombo dataProvider={categories} labelField=name/ Any Idea's Thanks, Roger
Re: [flexcoders] Cannot access a property or method of a null object reference
Is catalog misspelled? categories = event.result.catelog.category; If there's no catelog child of the XML root, then trying to access a child of that node will probably throw the error. Doug Roger Ross wrote: Hello, Working my way throught the Training From the Source turorial and ran into this error message. Not sure why I am getting it. I compared my code to the completed code for the lesson and it looks the same with no problems when I compile it. TypeError: Error #1009: Cannot access a property or method of a null object reference. at Dashboard/::catHandler() at Dashboard/__catRPC_result() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent() at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler http://www.adobe.com/2006/flex/mx/internal::resultHandler() at mx.rpc::Responder/result() at mx.rpc::AsyncRequest/acknowledge() at ::DirectHTTPMessageResponder/completeHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete() Here is a copy of the code that it has me write with the comboBox that is to receive the data: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml layout=horizontal creationComplete=catRPC.send() mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var categories:ArrayCollection=new ArrayCollection(); private function catHandler(event:ResultEvent):void{ categories = event.result.catelog.category; var catObj:Object = new Object(); catObj.name = All; catObj.categoryID = 0; categories.addItemAt(catObj, 0); catCombo.selectedIndex = 0; } ]] /mx:Script mx:HTTPService id=catRPC url=http://www.flexgrocer.com/category.xml http://www.flexgrocer.com/category.xml result=catHandler(event)/ mx:ComboBox id=catCombo dataProvider={categories} labelField=name/ Any Idea's... Thanks, Roger
Re: [flexcoders] Cannot access a property or method of a null object reference
most likely the setting of the selectedIndex is what is causing that error. Its trying to set a property to a component that doesnt exist yet. On 1/25/07, Roger Ross [EMAIL PROTECTED] wrote: Hello, Working my way throught the Training From the Source turorial and ran into this error message. Not sure why I am getting it. I compared my code to the completed code for the lesson and it looks the same with no problems when I compile it. TypeError: Error #1009: Cannot access a property or method of a null object reference. at Dashboard/::catHandler() at Dashboard/__catRPC_result() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction () at flash.events::EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent() at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler() at mx.rpc::Responder/result() at mx.rpc::AsyncRequest/acknowledge() at ::DirectHTTPMessageResponder/completeHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction () at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete() Here is a copy of the code that it has me write with the comboBox that is to receive the data: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=horizontal creationComplete=catRPC.send() mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var categories:ArrayCollection=new ArrayCollection(); private function catHandler(event:ResultEvent):void{ categories = event.result.catelog.category; var catObj:Object = new Object(); catObj.name = All; catObj.categoryID = 0; categories.addItemAt(catObj, 0); catCombo.selectedIndex = 0; } ]] /mx:Script mx:HTTPService id=catRPC url=http://www.flexgrocer.com/category.xml; result=catHandler(event)/ mx:ComboBox id=catCombo dataProvider={categories} labelField=name/ Any Idea's… Thanks, Roger -- http://indeegrumpee.spaces.live.com/