Solved

Error #1009: Cannot access a property or method of a null object reference.

Posted on 2011-03-10
5
730 Views
Last Modified: 2012-06-27
I get the null object reference in my code and I just dont know why. Below is a simple example. Can anyone please help me fix this issue?

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx" 
					   width="1000" height="600" 
					   xmlns:components="components.*"
					   creationComplete="init(event)">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;

			protected function init(event:FlexEvent):void
			{
				textArea.text =  tela_resp.resp3.text;
			}

		]]>
	</fx:Script>
	
		<components:tela_apres_resultados id="tela_resp" visible="true" />
		<s:TextArea id="textArea"/>
	

</s:WindowedApplication>


component:
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" 
				   xmlns:s="library://ns.adobe.com/flex/spark" 
				   xmlns:mx="library://ns.adobe.com/flex/mx" currentState="{stateTelaResp}"
				   xmlns:claire="claire.com.*"
				   horizontalAlign="center" verticalAlign="middle">
	<fx:Script>
		<![CDATA[
			[Bindable]
			public var image:String;
			[Bindable]
			public var texto_resp1:String;
			[Bindable]
			public var texto_resp2:String;
			[Bindable]
			public var texto_resp3:String;
			[Bindable]
			public var texto_resp4:String;
			[Bindable]
			public var texto_resp5:String;
			
			[Bindable]
			public var stateTelaResp:String;

			
		]]>
	</fx:Script>
	<s:states>
		<s:State name="State1"/>
		<s:State name="State2"/>
		<s:State name="State3"/>
		<s:State name="State4"/>
		<s:State name="State5"/>

	</s:states>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
<s:HGroup horizontalAlign="left" verticalAlign="middle">
	<s:TextArea width="80" height="60" id="txt_resp1" text="{texto_resp1}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
	<mx:Spacer height="20"/>
	<mx:TextInput width="80" height="30" id="resp1" focusIn="myQwertyKeypad.newFocus(resp1)" />
</s:HGroup>
<s:HGroup horizontalAlign="left" verticalAlign="middle"  includeIn="State2,State3,State4,State5">
	<s:TextArea width="80" height="60" id="txt_resp2" text="{texto_resp2}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
	<mx:Spacer height="20"/>
	<mx:TextInput width="80" height="30" id="resp2" focusIn="myQwertyKeypad.newFocus(resp2)" />
</s:HGroup>
<s:HGroup horizontalAlign="left" verticalAlign="middle"  includeIn="State3,State4,State5">
	<s:TextArea width="80" height="60" id="txt_resp3" text="{texto_resp3}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
	<mx:Spacer height="20"/>
	<mx:TextInput width="80" height="30" id="resp3" focusIn="myQwertyKeypad.newFocus(resp3)" text=""/>
</s:HGroup>
<s:HGroup horizontalAlign="left" verticalAlign="middle"  includeIn="State4,State5">
	<s:TextArea width="80" height="60" id="txt_resp4" text="{texto_resp4}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
	<mx:Spacer height="20"/>
	<mx:TextInput width="80" height="30" id="resp4" focusIn="myQwertyKeypad.newFocus(resp4)" text=""/>
</s:HGroup>
<s:HGroup horizontalAlign="left" verticalAlign="middle"  includeIn="State5">
	<s:TextArea width="80" height="60" id="txt_resp5" text="{texto_resp5}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
	<mx:Spacer height="20"/>
	<mx:TextInput width="80" height="30" id="resp5" focusIn="myQwertyKeypad.newFocus(resp5)" text=""/>
</s:HGroup>
<mx:Spacer height="40"/>
	<claire:Qwerty id="myQwertyKeypad" inputControl="{resp1}" width="100%"/>

</s:VGroup>

Open in new window

0
Comment
Question by:C_Schlottfeldt
  • 3
5 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 35108692
>> I get the null object reference in my code
At what line?

Please post the complete stack trace
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 35108731
I think you are referencing textArea.text before it has been created

try this:

 
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx" 
					   width="1000" height="600" 
					   xmlns:components="components.*"
					   creationComplete="init(event)">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;

[Bindable] private var textAreaTxt:String;

			protected function init(event:FlexEvent):void
			{
				textAreaTxt =  tela_resp.resp3.text;
			}

		]]>
	</fx:Script>

	<components:tela_apres_resultados id="tela_resp" visible="true" />
	<s:TextArea id="textArea" text={textAreaTxt}/>

Open in new window


Regards
Gary
0
 
LVL 37

Accepted Solution

by:
zzynx earned 250 total points
ID: 35108759
I guess it is at this line:

>> textArea.text =  tela_resp.resp3.text;

Sure resp3 is already initialized when you call this?

You have this:
<s:HGroup horizontalAlign="left" verticalAlign="middle"  includeIn="State3,State4,State5">
      <s:TextArea width="80" height="60" id="txt_resp3" text="{texto_resp3}" borderVisible="false" selectable="false" fontSize="18" verticalAlign="middle" textAlign="center" fontWeight="normal" editable="false" enabled="false"/>
      <mx:Spacer height="20"/>
      <mx:TextInput width="80" height="30" id="resp3" focusIn="myQwertyKeypad.newFocus(resp3)" text=""/>

includeIn="State3,State4,State5"

Are you sure that initially you're in one of those states?
I don't think so, and that's why resp3 (that TextInput) is not yet available/created/initialzed...
0
 

Author Closing Comment

by:C_Schlottfeldt
ID: 35108945
Indeed that was the fact. I didn´t know that the object were initialized just when their state was called and sustained. Thank you very much!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 35108983
You're welcome.
Thanx 4 axxepting
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Display recordset field HTML encoded 21 50
Can't play streaming video on event.on24.com 7 182
MVC and Angular 2 88
Windows Tool to Build Android and iOS App 3 51
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now