I have created one application in flex that is accessing the Java webservice using Actionscript3.0. In which I am getting the error during the accessing the one of the webservice method.That method is returning the list of child object I am taking this List of object in ArrayCollection class object.My code is:-
[Bindable]
private var photoFeed:Array;
public var user:SBTSWebService;
public function initApp():void
{
user = new SBTSWebService();
user.addSBTSWebServiceFaultEventListener(handleFaults);
}
public function displayString():void
{
// Instantiate a new Entry object.
var newEntry:GetSBTSMobileAuthentication = new GetSBTSMobileAuthentication();
newEntry.mobile=mobileno.text;
newEntry.password=password.text;
user.addgetSBTSMobileAuthenticationEventListener(authenticationResult);
user.getSBTSMobileAuthentication(newEntry);
}
public function handleFaults(event:FaultEvent):void
{
Alert.show("A fault occured contacting the server. Fault message is: " + event.fault.faultString);
}
public function authenticationResult(event:GetSBTSMobileAuthenticationResultEvent):void
{
if(event.result != null)
{
if(event.result._return > 0)
{
var UserId:int = event.result._return;
getChildList(UserId);
viewstack2.selectedIndex=1;
}
else
{
Alert.show("Authentication fail");
}
}
}
public function getChildList(userId:int):void
{
var childEntry:GetSBTSMobileChildrenInfo = new GetSBTSMobileChildrenInfo();
childEntry.UserId = userId;
user.addgetSBTSMobileChildrenInfoEventListener(sbtsChildrenInfoResult);
user.getSBTSMobileChildrenInfo(childEntry);
}
public function sbtsChildrenInfoResult(event:GetSBTSMobileChildrenInfoResultEvent):void
{
if(event.result != null && event.result._return!=null)
{
photoFeed = event.result._return as Array;
childid.dataProvider = photoFeed;
}
}
]]>
<mx:Move id="hideEffect"
xTo="-500" />
<mx:Move id="showEffect"
xFrom="500" />
<mx:Panel width="500" height="300"
headerColors="[#000000,#FFFFFF]">
<mx:TabNavigator id="viewstack2"
selectedIndex="0"
historyManagementEnabled="false"
width="100%" height="100%">
<mx:Form label="Login Form"
hideEffect="{hideEffect}" showEffect="{showEffect}">
<mx:FormItem>
<mx:TextInput id="mobileno"/>
</mx:FormItem>
<mx:FormItem>
<mx:TextInput id="password"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Login" click="displayString()"/>
</mx:FormItem>
</mx:Form>
<mx:Form label="Child List"
hideEffect="{hideEffect}" showEffect="{showEffect}">
<mx:DataGrid id="childid" visible="false"/>
<mx:Button label="click here to see location"
click="viewstack2.selectedIndex=2" />
</mx:Form>
<mx:Form label="Bus Location"
hideEffect="{hideEffect}" showEffect="{showEffect}">
<mx:Text text="" />
</mx:Form>
<mx:Form label="Trace Path"
hideEffect="{hideEffect}" showEffect="{showEffect}">
<mx:Text text="" />
</mx:Form>
</mx:TabNavigator>
</mx:Panel>
I am getting the error like “TypeError: Error #1009: Cannot access a property or method of a null object reference”.when the line “photoFeed = event.result._return as Array;” is compile.
Please help me to remove this error.
It seems strange that you are getting the error on that line as you have already made the check that both result and result._return are not null. It is more likely that the line…
…is causing the error because
childidis null? This would probably be because you tab navigator has not created the second tab yet. Try adding creationPolicy=”all” to the tab navigator to make sure it has been created.By default it is set to ‘auto’ which means it will only create panels other than the default when you click on them.