Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The goal of the tutorial is to teach the user how to how to record live broadcast.

757 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

19 Experts available now in Live!

Get 1:1 Help Now