Solved

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

Posted on 2011-03-10
5
743 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

628 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