获取 TypeError:错误 #1009:无法访问空对象引用的属性或方法
我创建了用于在 Flex 桌面应用程序中登录的小应用程序。我在其中引用用于登录的 Web 服务方法,为此创建了 Authentication 类。现在我想为手机号码引用不同的 Textinput 值,为密码引用不同的 Textinput 值。在我的身份验证课程中。
为此,我创建了 mxml 类的对象。并使用它我在我的操作脚本类中获取移动无值和密码值。
这是我的代码:-
SBTS.mxml 文件
<?xml version="1.0" encoding="utf-8"?>
<!-- usingas/AccessingPackagedClasses.mxml -->
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function login():void
{
var User:Authentication;
User = new Authentication();
User.authentication();
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%" layout="absolute">
<mx:TabNavigator width="100%" height="100%" id="viewstack2">
<mx:Form label="Login Form" id="loginform">
<mx:FormItem label="Mobile no:">
<mx:TextInput id="mobileno"/>
</mx:FormItem>
<mx:FormItem label="Password:">
<mx:TextInput displayAsPassword="true" id="password" />
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Login" click="login()"/>
</mx:FormItem>
</mx:Form>
<mx:Form label="Child List">
<mx:Label width="100%" color="blue"
text="Select Child."/>
</mx:TabNavigator>
</mx:Panel>
</mx:WindowedApplication>
动作脚本类:-
package src
{
import adobe.utils.XMLUI;
import generated.webservices.*;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
public class Authentication
{
[Bindable]
private var childName:ArrayCollection;
[Bindable]
private var childId:ArrayCollection;
private var photoFeed:ArrayCollection;
private var arrayOfchild:Array;
private var newEntry:GetSBTSMobileAuthentication;
public var user:SBTSWebService;
public var mxmlobj:SBTS;
public function authentication():void
{
user =
new SBTSWebService();
if(user!=null)
{
user.addSBTSWebServiceFaultEventListener(handleFaults);
user.addgetSBTSMobileAuthenticationEventListener(authenticationResult);
newEntry =
new GetSBTSMobileAuthentication();
if(newEntry!=null)
{
mxmlobj =
new SBTS();
if(mxmlobj != null)
{
newEntry.mobile = mxmlobj.mobileno.text; // Getting error here error mention below
newEntry.password= mxmlobj.password.text;
}
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 && event.result._return>0)
{
if(event.result._return > 0)
{
var UserId:int = event.result._return;
if(mxmlobj != null)
{
mxmlobj.loginform.enabled =
false;
mxmlobj.viewstack2.selectedIndex=1;
}
}
else
{
Alert.show(
"Authentication fail");
}
}
}
}
}
我收到此错误:-
TypeError:错误#1009:无法访问空对象引用的属性或方法。
位于 SBTSBusineesObject::Authentication/authentication()[E:\Users\User1\Documents\Fl ex Builder 3\SBTS\src\SBTSBusineesObject\Authentication.as:35]
在 SBTS/login()[E:\Users\User1\Documents\Flex Builder 3\SBTS\src\SBTS.mxml:12]
在 SBTS/___SBTS_Button1_click()[E:\Users\User1\Documents\Flex Builder 3\SBTS\src\SBTS.mxml:27]
请帮助我删除此错误。
I have created small application for login in flex desktop application. In which I am refering webservice method for login for this have created the Authentication class. Now I want to refer different Textinput value for mobile no and Textinput value for password. In my Authentication class.
for this I have created the object of mxml class.And using this I am getting the mobile no value and password value in My Action script class.
This my code :-
SBTS.mxml file
<?xml version="1.0" encoding="utf-8"?>
<!-- usingas/AccessingPackagedClasses.mxml -->
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function login():void
{
var User:Authentication;
User = new Authentication();
User.authentication();
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%" layout="absolute">
<mx:TabNavigator width="100%" height="100%" id="viewstack2">
<mx:Form label="Login Form" id="loginform">
<mx:FormItem label="Mobile no:">
<mx:TextInput id="mobileno"/>
</mx:FormItem>
<mx:FormItem label="Password:">
<mx:TextInput displayAsPassword="true" id="password" />
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Login" click="login()"/>
</mx:FormItem>
</mx:Form>
<mx:Form label="Child List">
<mx:Label width="100%" color="blue"
text="Select Child."/>
</mx:TabNavigator>
</mx:Panel>
</mx:WindowedApplication>
Action script class :-
package src
{
import adobe.utils.XMLUI;
import generated.webservices.*;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
public class Authentication
{
[Bindable]
private var childName:ArrayCollection;
[Bindable]
private var childId:ArrayCollection;
private var photoFeed:ArrayCollection;
private var arrayOfchild:Array;
private var newEntry:GetSBTSMobileAuthentication;
public var user:SBTSWebService;
public var mxmlobj:SBTS;
public function authentication():void
{
user =
new SBTSWebService();
if(user!=null)
{
user.addSBTSWebServiceFaultEventListener(handleFaults);
user.addgetSBTSMobileAuthenticationEventListener(authenticationResult);
newEntry =
new GetSBTSMobileAuthentication();
if(newEntry!=null)
{
mxmlobj =
new SBTS();
if(mxmlobj != null)
{
newEntry.mobile = mxmlobj.mobileno.text; // Getting error here error mention below
newEntry.password= mxmlobj.password.text;
}
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 && event.result._return>0)
{
if(event.result._return > 0)
{
var UserId:int = event.result._return;
if(mxmlobj != null)
{
mxmlobj.loginform.enabled =
false;
mxmlobj.viewstack2.selectedIndex=1;
}
}
else
{
Alert.show(
"Authentication fail");
}
}
}
}
}
I am getting this error :-
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SBTSBusineesObject::Authentication/authentication()[E:\Users\User1\Documents\Fl ex Builder 3\SBTS\src\SBTSBusineesObject\Authentication.as:35]
at SBTS/login()[E:\Users\User1\Documents\Flex Builder 3\SBTS\src\SBTS.mxml:12]
at SBTS/___SBTS_Button1_click()[E:\Users\User1\Documents\Flex Builder 3\SBTS\src\SBTS.mxml:27]
Please help me to remove this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为MXML文件还没有添加到显示列表中。 Flash 播放器是单线程的,不会按照您的代码认为的方式暂停操作。 mobileno 为 null,因为该对象已创建,但它的子级都没有创建。
Because the MXML file hasn't been added to the display list. The Flash player is single threaded and doesn't suspend operation in the way your code thinks it does. mobileno is null because the object has been created but none of it's children have.