Litson.JsonMapper.ToObject : object not set to an instance c#

I am working on a big project right now so what i am doing is converting the .exe application to .apk application and fortunately i successfully converted it somehow there’s an error:

The whole error:

NullReferenceException: Object reference not set to an instance of an object at LitJson.JsonMapper.ToObject[ServerListJson] (System.String json) [0x00000] in :0 at LogoUI+c__Iterator2.MoveNext () [0x00000] in :0 at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in :0

So I’m suspecting that the error above is in the logoUI.cs only.

Am i calling it wrong. Can someone point out whats wrong on what i am doing.

LogoUI.cs

void TryShowIntro()
{
StartCoroutine(“CheckVersion”);
}
IEnumerator CheckVersion()
{
lbl_notification.text = NOTIFICATION[0];
yield return new WaitUntil(() => tzGlobal.Instance.VERSION != null);
FadeInVersion(tzGlobal.Instance.VERSION);
StartCoroutine(“CheckServer”);
}
IEnumerator CheckServer()
{
lbl_notification.text = NOTIFICATION[1];
// Load the URL.
CheckJSonManager.Instance._AwsDatacenterURL.SetURL();
// Download the notice.
WWW www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.NOTICE_URL);
yield return www;
// Save notice.
StreetUtility.SaveJson_mk2(www.text, string.Format(“{0}/notice.json”, Application.streamingAssetsPath));
// Download server list.
www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.SERVERLIST_URL);
yield return www;
// Store server list.
CheckJSonManager.Instance._ServerListJSon = LitJson.JsonMapper.ToObject(www.text);:wink:
// Server information to be connected is stored separately.
bool bFound = false;
ServerListJson pServerListJSon = CheckJSonManager.Instance._ServerListJSon;
int target_server_no = System.Int32.Parse(tzGlobal.Instance.VERSION.Split(‘.’)[2]);
for (int i = 0; i < pServerListJSon.serverData.Length; i++)
{
if (target_server_no == pServerListJSon.serverData*.serverNo)
__
{__
bFound = true;
_ServerData pServerList = pServerListJSon.serverData
;
NetworkManager.Instance.WebSocketServer.SESSION_NAME = pServerList.serverNo.ToString();
NetworkManager.Instance.WebSocketServer.SESSION_IP = pServerList.serverIP;
NetworkManager.Instance.WebSocketServer.SESSION_PORT = pServerList.serverPort;
tzGlobal.Instance.LOGIN_URL = pServerList.publisherURL;
tzGlobal.Instance.JOIN_URL = pServerList.joinURL;
tzGlobal.Instance.STREAMING_URL = pServerList.streamingURL;
break;
}
}
if (!bFound)
{_
// Debug.LogWarning(“ServerList_mk2.json does not find the required server number. Use the first server information.”);
Debug.LogWarning(“pc_version / ph / check / serverList.json does not find the required server number. Use the first server information.”);
ServerData pServerList = pServerListJSon.serverData[0];
NetworkManager.Instance.WebSocketServer.SESSION_NAME = pServerList.serverNo.ToString();
NetworkManager.Instance.WebSocketServer.SESSION_IP = pServerList.serverIP;
NetworkManager.Instance.WebSocketServer.SESSION_PORT = pServerList.serverPort;
tzGlobal.Instance.LOGIN_URL = pServerList.publisherURL;
tzGlobal.Instance.JOIN_URL = pServerList.joinURL;
tzGlobal.Instance.STREAMING_URL = pServerList.streamingURL;
_
}
// Auto-connect after a while.
StartCoroutine(“GoToLoginSceneAutomatically”);
EnableSkip(“auto”);
}_
What i tried so far is this.
1.) I print out.
- Debug.Log("www notice url= " + CheckJsonManager.Instance.AwsDatacenterURL.NOTICE_URL);
Output
jar:file:///data/app/com.steet383.rh.google-1/base.apk!/assets/notice.json
- Debug.Log("www serverlist url= " + CheckJSonManager.Instance.AwsDatacenterURL.SERVERLIST_URL);*
Output
jar:file:///data/app/com.steet383.rh.google-1/base.apk!/assets/serverList.json
Now this line of code
// Save the server list.

CheckJSonManager.Instance._ServerListJSon = LitJson.JsonMapper.ToObject(www.text);:wink:
I guess because i put a debug.log and it doesn’t proceed to that line anymore.
It works on UNITY_STANDALONE but when i tried to change the platform to UNITY_ANDROIDthis line gives me the error. Is this code
CheckJSonManager.Instance._ServerListJSon = LitJson.JsonMapper.ToObject(www.text);:wink:
not suitable for android??
Thank you in advance guys.

Check www.error.
If there is “java.net.MalformedURLException” add protocol prefix to URL, e.g. “http://”.

1 Like

Okay i’ll try this one and i’ll get back to you thank you .

I’ll write it like this

CheckJSonManager.Instance._AwsDatacenterURL.SetURL();

// notice를 다운로드한다 ( download 'notice.json ).
WWW www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.NOTICE_URL);
yield return www;

//Debug PK 12/13/2017
Debug.Log("www notice url = " + CheckJSonManager.Instance._AwsDatacenterURL.NOTICE_URL);

// notice를 저장한다. ( save ‘notice.json’ )
StreetUtility.SaveJson_mk2(www.text, string.Format(“{0}/notice.json”, Application.streamingAssetsPath));

// (Download server list) 서버 리스트를 다운로드한다.
www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.SERVERLIST_URL);
yield return www;

Debug.Log("www serverlist url = " + CheckJSonManager.Instance._AwsDatacenterURL.SERVERLIST_URL);

if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);:wink:
}

Is this right?

I have this error java.net.MalformedURLException: Protocol not found: /mc_version/ph/check/serverList.json

Did you try insering the protocol prefix to the address?

Yeah and i have this aws server that is like this

dataCenter:{ https://********.amazonaws.com }

script:
standalone platform
serverListJsonURL = string.Format(“{0}/pc_version/ph/check/serverList.json”, DataCenter_BaseURL );
android platform
serverListJsonURL = string.Format(“{0}/mc_version/ph/check/serverList.json”, DataCenter_BaseURL );

and putting it on the url like this https://********.amazonaws.com/pc_version/ph/check/serverList.json

it downloads the file but when i tried it on android it doesn’t why is that?

my whole script for that sir is like this

public class ReadOnlyString
{
string DataCenter_BaseURL;
public string DATACENTER_URL
{
get { return DataCenter_BaseURL; }
}

// Json
private string checkServerStatusJsonURL;
public string CheckServerStatusJsonURL
{
//get { return checkServerStatusJsonURL; }
get { return null; }
}

private string macAddressJsonURL;
public string MacAddressJsonURL
{
//get { return macAddressJsonURL; }
get { return null; }
}

private string serverListJsonURL;
public string SERVERLIST_URL
{
get { return serverListJsonURL; }
}

public string NOTICE_URL;

DealerServerJson dealerServerJson;
public DealerServerJson DEALER_SERVER_JSON
{
get { return dealerServerJson; }
}

public void SetURL()
{
// DataCenter URL ( 데이터센터 URL)
#if UNITY_ANDROID
string path = string.Format(“{0}/datacenter.json”, Application.streamingAssetsPath);
Debug.Log("The path : " + path);

if (File.Exists(path))
{
WWW reader = new WWW(path);
try
{
CheckJSonManager.Instance._DataCenterJson = LitJson.JsonMapper.ToObject(reader.text);
DataCenter_BaseURL = CheckJSonManager.Instance._DataCenterJson.dataCenter;
}
catch(Exception ex)
{
Debug.Log(“path :” + path + “\n” + ex);
}
}
path = string.Format(“{0}/dealerserver.json”, Application.streamingAssetsPath);
if (File.Exists(path))
{
WWW reader = new WWW(path);
try
{
Debug.Log(“************************* DealerServer.JSON *************************”);
CheckJSonManager.Instance._DealerServerJson = LitJson.JsonMapper.ToObject(reader.text);
}
catch (Exception ex)
{
Debug.Log(“Path : " + path + “\n” + ex);
}
} else
{
CheckJSonManager.Instance._DealerServerJson = new DealerServerJson();
}
// (Server list URL) 서버리스트 URL.
// (Try for mobile version - PK 12/13/2017)
// Changed the
// serverListJsonURL = string.Format(”{0}/pc_version/ph/check/serverList.json", DataCenter_BaseURL);
// NOTICE_URL = string.Format(“{0}/pc_version/ph/check/notice.json”, DataCenter_BaseURL);
//to
serverListJsonURL = string.Format(“{0}/mc_version/ph/check/serverList.json”, DataCenter_BaseURL );
NOTICE_URL = string.Format(“{0}/mc_version/ph/check/notice.json”, DataCenter_BaseURL);

#elif UNITY_IOS

#elif UNITY_STANDALONE
string path = string.Format(“{0}/datacenter.json”, Application.streamingAssetsPath);
if (File.Exists(path)) {
StreamReader reader = new StreamReader(path);
try
{
CheckJSonManager.Instance._DataCenterJson = LitJson.JsonMapper.ToObject(reader.ReadToEnd().Trim());
DataCenter_BaseURL = CheckJSonManager.Instance._DataCenterJson.dataCenter;
}
catch (Exception ex)
{
Debug.LogError("path : " + path + “\n” + ex);
}
reader.Close();
}

// (Get dealer server connection information) 딜러서버 접속 정보를 가져온다.
// (If the json file below is present, 'I am a dealer console) 아래 json파일이 존재하면, ‘나는 딜러콘솔이다’
path = string.Format(“{0}/dealerserver.json”, Application.streamingAssetsPath);
if (File.Exists(path))
{
StreamReader reader = new StreamReader(path);
try
{
Debug.Log(“********************* DealerServer.JSON ***************************”);
CheckJSonManager.Instance._DealerServerJson = LitJson.JsonMapper.ToObject(reader.ReadToEnd().Trim());
}
catch (Exception ex)
{
Debug.LogError("path : " + path + “\n” + ex);
}
reader.Close();
}
else
{
CheckJSonManager.Instance._DealerServerJson = new DealerServerJson();
}

// (Server list URL) 서버리스트 URL.
serverListJsonURL = string.Format(“{0}/pc_version/ph/check/serverList.json”, DataCenter_BaseURL);
NOTICE_URL = string.Format(“{0}/pc_version/ph/check/notice.json”, DataCenter_BaseURL);

// 안쓰고 있는 URL.
//checkServerStatusJsonURL = string.Format(“{0}/check/CheckServerStatus_{1}.json”, DataCenter_BaseURL, ClientVersion.Instance.PublisherNick);
//macAddressJsonURL = string.Format(“{0}/check/MacAddress.json”, DataCenter_BaseURL);
//uIBackGroundURL = DataCenter_BaseURL + “/UIBackGround/”;
#endif

}
}

Does it still include a prefix here:

Debug.Log("The path : " + path);

No sir.

Double check that prefix is present everywhere you make a request from android.

I’ll get back to you sir