简体   繁体   English

TypeError:错误#1009:无法访问空对象引用的属性或方法

[英]TypeError: Error #1009: Cannot access a property or method of a null object reference

I get this error when i launch the application(flash type with dismiss all and continue) and i'm out of ideas: 启动应用程序时,出现此错误(关闭所有类型的Flash类型,然后继续),但我没有主意:

TypeError: Error #1009: Cannot access a property or method of a null object reference. TypeError:错误#1009:无法访问空对象引用的属性或方法。 at Magazin/xmlService_resultHandler()[D:\\Documents and Settings\\chechu\\Adobe Flash Builder 4\\Magazin\\src\\Magazin.mxml:41] at Magazin/__xmlService_result()[D:\\Documents and Settings\\chechu\\Adobe Flash Builder 4\\Magazin\\src\\Magazin.mxml:64] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at HTTPOperation/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E :\\dev\\4.x\\frameworks\\projects\\rpc\\src\\mx\\rpc\\http\\HTTPService.as:989] at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E :\\dev\\4.x\\frameworks\\projects\\rpc\\src\\mx\\rpc\\AbstractInvoker.as:318] at mx.rpc::Responder/result()[E:\\dev\\4.x\\frameworks\\projects\\rpc\\src\\mx\\rpc\\Responder.as:56] at mx.rpc::AsyncRequest/acknowledge()[E:\\dev\\4.x\\frameworks\\projects\\rpc\\src\\mx\\rpc\\AsyncRequest.as:84] at DirectHTTPMessageResponder/completeHandler()[E:\\dev\\4.x\\frameworks\\projects\\rpc\\src\\mx\\messaging\\channels\\DirectHTTPChannel.as:446] at flash.ev 在Magazin / xmlService_resultHandler()[D:\\ Documents and Settings \\ chechu \\ Adob​​e Flash Builder 4 \\ Magazin \\ src \\ Magazin.mxml:41]在Magazin / __ xmlService_result()[D:\\ Documents and Settings \\ chechu \\ Adob​​e Flash Builder 4 \\ Magazin \\ src \\ Magazin.mxml:64]在flash.events::EventDispatcher/dispatchEventFunction()在flash.events::EventDispatcher/dispatchEvent()在HTTPOperation / http://www.adobe.com/2006/flex / mx / internal :: dispatchRpcEvent()[E :\\ dev \\ 4.x \\ frameworks \\ projects \\ rpc \\ src \\ mx \\ rpc \\ http \\ HTTPService.as:989,位于mx.rpc :: AbstractInvoker / http:/ /www.adobe.com/2006/flex/mx/internal::resultHandler()[e :\\ dev \\ 4.x \\ frameworks \\ projects \\ rpc \\ src \\ mx \\ rpc \\ AbstractInvoker.as:318]在mx。 rpc :: Responder / result()[E:\\ dev \\ 4.x \\ frameworks \\ projects \\ rpc \\ src \\ mx \\ rpc \\ Responder.as:56] at mx.rpc :: AsyncRequest / acknowledge()[E: DirectHTTPMessageResponder / completeHandler()处的\\ dev \\ 4.x \\ frameworks \\ projects \\ rpc \\ src \\ mx \\ rpc \\ AsyncRequest.as:84] [E:\\ dev \\ 4.x \\ frameworks \\ projects \\ rpc \\ src \\ mx \\ messaging \\ channels \\ DirectHTTPChannel.as:446],位于flash.ev ents::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete() ents :: EventDispatcher / dispatchEventFunction()在flash.events::EventDispatcher/dispatchEvent()在flash.net::URLLoader/onComplete()

The main application: 主要应用:

  import events.ProductEvent;

  import mx.collections.ArrayCollection;
  import mx.controls.Alert;
  import mx.events.FlexEvent;
  import mx.rpc.events.FaultEvent;
  import mx.rpc.events.ResultEvent;

  import valueObject.ImageClass;
  [Bindable]
  public  var  imagesCollection:ArrayCollection;
  protected function xmlService_faultHandler(event:FaultEvent):void
  {
    Alert.show("meeah");

  }


  protected  function xmlService_resultHandler(event:ResultEvent):void
  {
    var imageCollection:ArrayCollection=event.result.Images.image ;
    var imData:ImageClass;
    for each(var im:Object in imageCollection)
    {
      imData=new ImageClass();
      imData.url=im.url;
      imData.big_url=im.big_url;
      imData.cat=im.cat;
      imData.descript=im.descript;
      imData.price=im.price;
      imagesCollection.addItem(imData); line:41

    }
    Alert.show("gg");
  }
  [Bindable]
  public var mama:ArrayCollection=new ArrayCollection();



  protected function gallery1_addToCartHandler(event:ProductEvent):void
  {
     mama.addItem(event);
    currentState="cart"; 
      }

    ]]>
</fx:Script>
  <s:states>
    <s:State name="normal"/>
    <s:State name="cart"/>
  </s:states>
  <fx:Declarations>    
    <s:HTTPService id="xmlService"  line 64
                   url="dataXml/pics.xml" fault="xmlService_faultHandler(event)" 
                   result="xmlService_resultHandler(event)"/>

  </fx:Declarations>

  <components:Gallery imagesArray="{imagesCollection}" addToCart="gallery1_addToCartHandler(event)"   />

  <components:cart  x="500" y="300" itemRenderer="components.CartRenderer" dataProvider="{mama}"  />
</s:Application>

The Gallery component: 图库组件:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"   >
  <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
  </fx:Declarations>

  <fx:Metadata>
    [Event(name="addToCart",type="events.ProductEvent")]
  </fx:Metadata>

  <s:layout>
    <s:VerticalLayout/>
  </s:layout>

  <fx:Script>
    <![CDATA[
      import events.ProductEvent;

      import mx.collections.ArrayCollection;

      import valueObject.ImageClass;
      [Bindable]
      public var imagesArray:ArrayCollection;



      public function goa_clickHandler(event:MouseEvent):void
      {
        for (var i:uint=0; i<imagesArray.length;i++)
        {
          var objEvent:ProductEvent=new ProductEvent("addToCart",true);
          objEvent.imData=imagesArray[i] ;
          dispatchEvent(objEvent);
        }
      }
    ]]>
  </fx:Script>
  <s:SkinnableDataContainer id="cont"  dataProvider="{imagesArray}">

    <s:itemRenderer >

      <fx:Component>

        <s:ItemRenderer>

          <s:HGroup>
            <s:Label id="gagal" text="{data.price}"/>
            <mx:Image source="{data.url}" width="50" height="50" />
            <s:Button id="goa"  label="buy" click="outerDocument.goa_clickHandler(event)"/>
          </s:HGroup>

        </s:ItemRenderer>

      </fx:Component>



    </s:itemRenderer>

  </s:SkinnableDataContainer>


</s:Group>

The ProductEvent class: ProductEvent类:

package events
{
  import flash.events.Event;

  import valueObject.ImageClass;

  [Bindable]
  public class ProductEvent extends Event
  {

    public var imData:ImageClass;


    public function ProductEvent(type:String,bubbles:Boolean=true)
    {
      super(type,bubbles);


    }
    override public function clone():Event
    {
      var eventOb:ProductEvent=new ProductEvent(type,bubbles);
      eventOb.imData=this.imData;
      return eventOb;

    }
  }

The ImageClass: ImageClass:

package valueObject
 {
  [Bindable]
  public class ImageClass
  {
    public var url:String;
    public var big_url:String;
    public var descript:String;
    public var price:String;
    public var cat:String;

    public function ImageClass()
    {
      /*this.url=url;
      this.big_url=big_url;
      this.descript=descript;
      this.price=price;
      this.cat=cat;*/
    }
  }
}

and the xml: 和xml:

<?xml version="1.0"?>
<Images>
 <image> 
  <url>poze/pics/IMG_1163.jpg</url>
  <big_url>poze/big_pics/IMG_1163.jpg </big_url>
  <descript>P</descript>
  <price>99.99</price>
  <cat>A</cat>
 </image>
 <image>
  <url>poze/pics/IMG_1175.jpg</url>
  <big_url>poze/big_pics/IMG_1175.jpg</big_url>
  <descript>U</descript>
  <price>99.99</price>
  <cat>A</cat>
 </image>
 <image>
  <url>poze/pics/IMG_1186.jpg</url>
  <big_url>poze/big_pics/IMG_1186.jpg</big_url>
  <descript>L</descript>
  <price>99.99</price>
  <cat>A</cat>
 </image>

You're accessing imagesCollection variable in line 41, but haven't initialized it - it still contains null 您正在第41行中访问imagesCollection变量,但尚未对其进行初始化-它仍包含null

Either change 要么改变

[Bindable]
public  var  imagesCollection:ArrayCollection;

To

[Bindable]
public  var  imagesCollection:ArrayCollection = new ArrayCollection();

or add 或添加

imagesCollection  = new ArrayCollection();

to the beginning of xmlService_resultHandler method. xmlService_resultHandler方法的开头。

Remember... 记得...

Whenever there is a null reference error then you need to initialize the variable that you are using. 只要存在空引用错误,就需要初始化所使用的变量。

Say if you are using Array or ArrayCollection 说如果您使用ArrayArrayCollection

  • you need to do: yourArrayVarriable = new Array(); 您需要做: yourArrayVarriable = new Array(); inside the function or 在函数内部或
  • you need to do: yourArrayCollectionVarriable = new ArrayCollection(); 您需要执行以下操作: yourArrayCollectionVarriable = new ArrayCollection(); inside the function 在函数内部

and then start using yourArrayVarriable or yourArrayCollectionVarriable to store the values 然后开始使用yourArrayVarriableyourArrayCollectionVarriable存储值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Adobe Flex 错误类型错误:错误 #1009:无法访问 null object 参考的属性或方法 - Adobe Flex Error TypeError: Error #1009: Cannot access a property or method of a null object reference Flex错误#1009:无法访问空对象引用的属性或方法 - Flex Error #1009: Cannot access a property or method of a null object reference Flex 错误 #1009:无法访问 null object 引用的属性或方法 - Flex Error #1009: Cannot access a property or method of a null object reference 如何解决TypeError:错误#1009:从Flex 3调用swf时无法访问空对象引用的属性或方法 - How to solve TypeError: Error #1009: Cannot access a property or method of a null object reference while calling swf from flex 3 AS3错误代码1009-无法访问空对象引用的属性或方法 - AS3 Error Code 1009 - Cannot access a property or method of a null object reference .mxml和.as问题:错误#1009:无法访问空对象引用的属性或方法 - .mxml and .as issue: Error #1009: Cannot access a property or method of a null object reference Flex:如何解决错误#1009:无法访问空对象引用的属性或方法 - Flex:how to solve Error #1009: Cannot access a property or method of a null object reference Flex中的“无法访问空对象引用的属性或方法。”错误 - “Cannot access a property or method of a null object reference.” error in Flex 错误:无法在Flex中访问空对象引用的属性或方法 - Error: Cannot access a property or method of a null object reference in flex 无法访问空对象引用的属性或方法 - Cannot access a property or method of a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM