我在flex中创建了一个使用Actionscript3.0访问Java Web服务的应用程序。我在访问其中一个webservice方法时得到错误。该方法返回子对象列表我在ArrayCollection类对象中获取此对象列表。我的代码是: -
[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>
我收到的错误如“TypeError:错误#1009:无法访问空对象引用的属性或方法”。当行“photoFeed = event.result._return as Array;”时是编译。 请帮我删除此错误。
答案 0 :(得分:0)
由于您已经检查结果和result._return都不为null,因此您在该行上收到错误似乎很奇怪。线路更可能......
childid.dataProvider = photoFeed;
...导致错误,因为childid
为空?这可能是因为您的选项卡导航器尚未创建第二个选项卡。尝试将creationPolicy =“all”添加到选项卡导航器中以确保它已创建。
<mx:TabNavigator id="viewstack2"
selectedIndex="0"
creationPolicy="all"
historyManagementEnabled="false"
width="100%" height="100%">
默认设置为“自动”,这意味着当您点击它们时,它只会创建默认面板以外的面板。