閱讀337 返回首頁    go 京東網上商城


Object reference not set to an instance of an object.

        今天從A界麵跳轉到B界麵,並調用B界麵中函數的時候,會報錯“Object reference not set to an instance of an object.”這個錯誤,是什麼原因呢?
代碼中聲明了這麼一個變量(在從A界麵跳轉到B界麵的過程中都沒給KSRQ這個變量賦值)
public string KSRQ ;
當用到
this.KSRQ.Trim() != ""
的時候,會報出“Object reference not set to an instance of an object.”這個錯誤。
解決方法:
public string KSRQ=string.Empty ;
原因:未將對象引用到對象的實例.也就是沒有實例化一個對象。當聲明了變量,但是沒有賦值,仍然為null.用的時候就會報錯.

最後更新:2017-04-03 16:49:14

  上一篇:go xmpp即時通訊四
  下一篇:go android優化之省電