Object reference not set to an instance of an object. C # (in the installation)

0

By the error message, it was understood that there is an uninstantiated object, in which I would be referring.

Error:

However,thissameapplicationworksperfectlyonthedevelopmentcomputer,whenIgeneratetheinstallerandinstallonanothermachinethiserroroccurs.

------------------Specifications:

  

Application:Desktop.

    

VisualStudio:2013.

    

Methodsusedtogeneratetheinsterver:

    

1stPublish(withrequirementfiles).

    

2ndCreationofaSetup-Wizardproject(VisualStudio2010style)

Inmyownforumsearchesandothers,thiserroroccursduringdevelopment,notinstallation.DoesanyoneknowthereallycorrectmethodofgeneratingtheinstallerinVisual2013

LoadPDV():

privatevoidCarregarPDV(){PDV=Model_PDV.Buscar(Ctrl_Configuracao.PDV.Id);txtPDV.Text=PDV.Descritivo;if(PDV.Status.Equals("False"))
        {
            txtSituacao.Text = "FECHADO";
            btnFechar.Enabled = false;
            btAbrir.Enabled = true;
            Ctrl_Configuracao.CaixaStatus = false;
            txtSituacao.BackColor = System.Drawing.Color.Red;
        }
        else
        {
            txtSituacao.Text = "ABERTO";
            btnFechar.Enabled = true;
            btAbrir.Enabled = false;
            Ctrl_Configuracao.CaixaStatus = true;
            txtSituacao.BackColor = System.Drawing.Color.Green;
        }
        Model_LogPDV LogCaixa = new Model_LogPDV();
        LogCaixa = Model_LogPDV.BuscaLog(Ctrl_Configuracao.PDV.Id);
        if (LogCaixa.ID_VENDA_START.Equals(""))
        {
            Ctrl_Configuracao.JaVendeu = false;
        }
    }

Bank Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Gaivota.Controller;
using Gaivota.View;
using Gaivota.Model;

namespace Gaivota.Model
{

    class Banco
    {
       public static SqlConnection Conexao = new SqlConnection("Data Source=" + Ctrl_Configuracao.Config.DataLink
             + "; Initial Catalog=Gaivota; User Id=sa; Password=123456; Integrated Security=false");

        public static void Abrir()
        {             
            try
            {
                Conexao.Open();
            }
            catch (Exception)
            {

                Ctrl_Msg.MensagemInforma(Ctrl_Msg.ErroAbrirBanco);
            }

        }
        public static void Fechar()
        {
            try
            {
                Conexao.Close();
            }
            catch (Exception)
            {

            }

        }
        public static string BuscarCodigoNext(string Tabela)
        {
            string CodigoNovo = "0";
            string sqlstring = "";
            try
            {

                sqlstring = "select ID from " + Tabela + " order by ID desc";
                SqlCommand Comando = new SqlCommand(sqlstring, Banco.Conexao);
                SqlDataReader Ler = Comando.ExecuteReader();

                if (Ler.Read())
                {
                    CodigoNovo = Ler["ID"].ToString();
                    Ler.Close();
                }
                CodigoNovo = (Convert.ToInt32(CodigoNovo) + 1).ToString();
            }
            catch (Exception)
            {

            }
            return (CodigoNovo);

        }
        public static string BuscarCodigoAtual(string Tabela)
        {
            string CodigoAtual = "0";
            string sqlstring = "";
            try
            {

                sqlstring = "select ID from " + Tabela + " order by ID desc";
                SqlCommand Comando = new SqlCommand(sqlstring, Banco.Conexao);
                SqlDataReader Ler = Comando.ExecuteReader();

                if (Ler.Read())
                {
                    CodigoAtual = Ler["ID"].ToString();
                    Ler.Close();
                }
                CodigoAtual = (Convert.ToInt32(CodigoAtual)).ToString();
            }
            catch (Exception)
            {

            }
            return (CodigoAtual);

        }


    }


}

Settings class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gaivota.Model;
using System.Windows.Forms;
using System.Xml;

namespace Gaivota.Controller
{
    class Ctrl_Configuracao
    {
        public static bool RespostaBanco;

        public static bool EstaBuscando;

        public static bool CaixaStatus;

        public static bool JaVendeu = true;

        public static Model_Produto Produto = new Model_Produto();

        public static Model_PDV PDV = new Model_PDV();

        public static Model_Usuario Usuario = new Model_Usuario();

        public static Model_Configuracao Config = new Model_Configuracao();

        public static Model_RelPDV RelPDV = new Model_RelPDV();

        public static string XML_Link = @"C:\Gaivota\config.xml";

        public static  Model_Configuracao LerXML()
        {
            Model_Configuracao Configuracao = new Model_Configuracao();
            Configuracao.PortaCOM = null;
            try
            {
                //Cria uma instância de um documento XML
                XmlDocument oXML = new XmlDocument();

                //carrega o arquivo XML
                oXML.Load(XML_Link);

                //Lê o filho de um Nó Pai específico 
                Configuracao.ModeloPrint = oXML.SelectSingleNode("config").ChildNodes[0].InnerText;
                Configuracao.PortaCOM = oXML.SelectSingleNode("config").ChildNodes[1].InnerText;
                Configuracao.Velocidade = oXML.SelectSingleNode("config").ChildNodes[2].InnerText;
                Configuracao.DataLink = oXML.SelectSingleNode("config").ChildNodes[3].InnerText;
            }
            catch (Exception)
            {
                Ctrl_Msg.MensagemInforma(Ctrl_Msg.ErroLerXML);
            }

            return Configuracao;
        }

        public static void SetConfig()
        {       

         Ctrl_Configuracao.Config  = Ctrl_Configuracao.LerXML();  


        }
        public static bool SomenteNumeros(int key)
        {
            bool x = true;

            if (key < 48 || key > 57)
            {
                if (key == 8)
                {
                    x = false;
                }
                else
                {
                    x = true;
                }
            }
            else
            {
                x = false;
            }

            return (x);
        }

    }
}
    
asked by anonymous 18.06.2016 / 15:18

1 answer

-1

The problem may be in the Equals(...) method, you need more details of your problem to know for sure what happens

The problem can be here:

PDV.Status.Equals("False");

Or here:

LogCaixa.ID_VENDA_START.Equals("");

If the PDV.Status or LogCaixa.ID_VENDA_START is null the mentioned error will occur, because the object is not instantiated.

I recommend that you replace .Equals(...) with ==

Then your method would look like this:

if (PDV.Status=="False")
{
   ...
}
    
18.06.2016 / 16:33