Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-10
5
Medium Priority
?
753 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

660 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