Solved

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

Posted on 2011-03-10
5
738 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
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 …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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