Помогите пожалуйста срочно!
Maksim sus36
Помогите пожалуйста срочно!
Помогите решить проблему:
NullReferenceException: Object reference not set to an instance of an object
DatabaseHandler.GetConnectionState () (at Assets/Scripts/DatabaseHandler.cs:56)
_LoginGUI.OnGUI () (at Assets/Scripts/_LoginGUI.cs:10)
вот скрипт
Database:using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Security.Cryptography;
using System.Data;
using System;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
public class DatabaseHandler : MonoBehaviour {
public string host, database, user, password;
public bool pooling = true;
private string connectionString;
private MySqlConnection con = null;
private MySqlCommand cmd = null;
private MySqlDataReader rdr = null;
private MD5 _md5Hash;
void Awake() {
DontDestroyOnLoad (this.gameObject);
connectionString = "Server" + host + "DataBase" + database + "User" + user + "Password" + password + ";Pooling=*";
if (pooling) {
connectionString += "true";
} else {
connectionString += "false";
}
try{
con = new MySqlConnection(connectionString);
con.Open();
Debug.Log("Msql State: "+con.State);
}catch (Exception e) {
Debug.Log (e);
}
}
void OnApplicationQuit() {
if (con != null) {
if (con.State.ToString() != "Closed") {
con.Close ();
Debug.Log ("MySql Connection Closed");
}
con.Dispose ();
}
}
public string GetConnectionState() {
return con.State.ToString ();
}
}
Скрипт 2 :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class _LoginGUI : MonoBehaviour {
public DatabaseHandler _msqlHongri;
void OnGUI() {
GUI.Label( new Rect (10, 10, 300, 30), "Msql Connection State: " + _msqlHongri.GetConnectionState() );
}
}
Ответы:
Андрей
Проверь, что именно у тебя в connectionString записано - перед тем, как ты new MySqlConnection делаешь.
Предлагаешь нам самым высчитывать, какая строка в твоём коде имеет номер 56?
|