0

Here is my code :

string playerwinnopairboth = "P  ";

IEnumerator WinLog_big_road()
{
    string[] historyvalue = { };
    historyvalue = tzPlayInfo.Instance.HistoryValue;
    /*-------------------------------*/
    NetworkManager.instance.WebSocketServer.OnCallBack_SC_WEBSOCKET_BcGametableHistory += CallBack_CS_WEBSOCKET_BcGametableHistory;
    /*-------------------------------*/
    DeleteChildrens(pos_big_road);
    yield return new WaitForEndOfFrame();
    for (int i = 0; i < rh.Const._HISTORY_COUNT_CARD_ * rh.Const._HISTORY_DECK_; i++)
    {
        int x = i % rh.Const._HISTORY_COUNT_CARD_;
        int y = i / rh.Const._HISTORY_COUNT_CARD_;

        float xl = 2.0f;
        float yl = -5.0f;

        GameObject o = Instantiate(prefab_big_road) as GameObject;
        o.transform.SetParent(pos_big_road);
        o.transform.localScale = Vector3.one;


        o.transform.localPosition = new Vector3(x * xl, y * yl, 0f);
        if (historyvalue.Contains(playerwinnopairboth))
        {
            //o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
            //NGUITools.SetActive(o, true);
            Debug.Log("PLAYER WIN, NO PAIR , NO PAIR");
        }
}


private void CallBack_CS_WEBSOCKET_BcGametableHistory(bool success, Int32 gametable_no, Int32 year, Int32 month, Int32 day, Int32 shoe_no, bc_gametable_history_list list)
{
    string s1 = "";
    for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
    {
        s1 += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
        s1 += ",";
    }
    tzPlayInfo.Instance.HistoryValue = s1.ToString().Split(',');
}

my tzPlayInfo values is like this:

private string[] historyvalue;
public string[] HistoryValue
{
    get { return historyvalue; }
    set { historyvalue = value; }

}

The Error is pointing me out here

 if (historyvalue.Contains(playerwinnopairboth))
        {
            //o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
            //NGUITools.SetActive(o, true);
            Debug.Log("PLAYER WIN, NO PAIR , NO PAIR");
        }

I don't know why it's giving me a null value . Could someone point out what i am doing wrong here. Thank you in advance for those who will help me...

Ginxxx
  • 1,602
  • 2
  • 25
  • 54
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – ProgrammingLlama Apr 27 '18 at 05:34
  • This value "tzPlayInfo.Instance.HistoryValue;" is probably null. Where is it assigned a value? – Matthias Hoste Apr 27 '18 at 05:34
  • 1
    "The Error is pointing me out here". The only thing there that can be null there (as an argument) is `playerwinnopairboth`, but we have no idea how you create that object. – ProgrammingLlama Apr 27 '18 at 05:35
  • 1
    @MatthiasHoste i assigned it here `tzPlayInfo.Instance.HistoryValue = s1.ToString().Split(',');` – Ginxxx Apr 27 '18 at 05:39
  • That doesn't assign anything to `playerwinnopairboth`. The *only* code you've shown that has anything to do with `playerwinnopairboth` is the `Contains` call. – Jon Skeet Apr 27 '18 at 05:39
  • @john i did it like this `string playerwinnopairboth = "P ";` . just passed the variable – Ginxxx Apr 27 '18 at 05:39
  • Oh wow I missed that, sorry. Are you sure that method is being called? Have you tried debugging? As @john pointed out. How is that object created? – Matthias Hoste Apr 27 '18 at 05:41
  • 1
    @TheGinxx009: My suspicion is that you've declare a local variable in one place, rather than assigning to a field. But because we've only got snippets of code rather than a complete piece of code, it's very hard to tell. Have you debugged into the code and checked what the value of `playerwinnopairboth` is before the call? – Jon Skeet Apr 27 '18 at 05:41
  • @DaisyShipton oh so you mean i must not do it like this `string[] historyvalue = { };historyvalue = tzPlayInfo.Instance.HistoryValue;` ?? – Ginxxx Apr 27 '18 at 05:42
  • No, I was talking about `playerwinnopairboth`. Assuming it's the `Contains` call that's failing (a stack trace would help to make that clear) then I expect `playerwinnopairboth` is null. (Having said that, you should learn about *automatically implemented properties* so you can just declare your property as `public string[] HistoryValue { get; set; }` without a separately-declared field. That's not the problem here, but it will help you have simpler code.) – Jon Skeet Apr 27 '18 at 05:43
  • OP, @Daisy means like [this](http://rextester.com/GIPZUB44335). Showing your code for creating `playerwinnopairboth` would help. – ProgrammingLlama Apr 27 '18 at 05:45
  • i'll edit my question to show you guys how i created it – Ginxxx Apr 27 '18 at 05:46
  • @john thats how i created my `playerwinnopairboth – Ginxxx Apr 27 '18 at 05:48
  • Are you 100% sure of the line where you are getting that exception? Can you inspect the value with the debugger just before the exception is thrown? – ProgrammingLlama Apr 27 '18 at 05:50
  • @john when i try to put a breakpoint it says it will not currently be hit. unable to find a corresponding location – Ginxxx Apr 27 '18 at 05:53
  • It sounds like you're running an old version of your code. You should clean and rebuild. Also check that you are running in debug mode. – ProgrammingLlama Apr 27 '18 at 05:55
  • @john it works now . the `historyvalue` value is null and my `playerwinnopairboth` has a value of "P " – Ginxxx Apr 27 '18 at 05:58

0 Answers0