erro com vetores c# / {“Referência de objeto não definida para uma instância de um objeto.”}
Amigos estou vindo no php e começando desenvolver em C#
As diferenças sao muitas, as ideias que tenho, quando vou aplicar dão erros.
Como exemplo, tenho um combobox html que preenchido dinamicamente, que pensei separar o código que seria o value do combobox e colocar como um valor em cada posição de um array ate ae tudo bem, mas não funciona.
A versão atual da o seguinte erro, alguém tem alguma ideia de como resolvo?
Da esse erro:
if (v != null)//MEU TRECHO PESQUISEI QUE TALVEZ SOLUCIONARIA O ERRO
>
"Referência de objeto não definida para uma instância de um objeto."
retorno/resultado é um json com os dados, da base, que enche o combobox.
O erro da quando debugando ele chega na linha do vetor!
An exception of type 'System.NullReferenceException' occurred in xyz.UI.dll but was not handled in user code
Additional information: Referência de objeto não definida para uma instância de um objeto.
em xyz.UI.Processxyz.Venda.AjaxPrazoMedioClienteEditar.ProcessRequest(HttpContext context)
em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
>
Citar
using System;
using System.Configuration;
using System.Data;
using System.Net.Http;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
namespace empresa.UI.ProcessEmpresa
{
/// <summary>
/// Summary description for AjaxPrazoMedioCliente
/// </summary>
public class AjaxPrazoMedioCliente : IHttpHandler
{
string[] v;//CRIACAO DO VETOR
public int i, j = 0;
public void ProcessRequest(HttpContext context)
{
Grupo = Convert.ToString(context.Request.QueryString["codgrupo"]);
temmontante = Convert.ToString(context.Request.QueryString["temmontante"]);
selecionado = Convert.ToString(context.Request.QueryString["selecionado"]);
temmontante = temmontante.Equals("") ? "0" : temmontante;
HttpClient client = null;
string retorno = string.Empty;
if (client == null)
{
* client = new HttpClient();*
* client.BaseAddress = new Uri(ConfigurationManager.AppSettings["url_servidor"]);*client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage resultado = client.GetAsync("xyz/Venda/PrazoMedio/" + Grupo + "/" + temmontante).Result;
retorno = resultado.Content.ReadAsStringAsync().Result;
if (resultado.StatusCode != System.Net.HttpStatusCode.NotFound)
{
if (retorno != "[]")
{
* sb.Append("<select name=\"txtpagpedido\" id=\"txtpagpedido\" onchange=\"HabilitarDescontoPromocional()\" style=\"width: 200px;\" >");*
* sb.Append("<option value=\"0\">Selecione..</option>");*JArray usuarioarrray = JArray.Parse(retorno);
foreach (JObject obj in usuarioarrray.Children<JObject>())
{
foreach (JProperty prop in obj.Properties())
{
* if (v** != null)//MEU TRECHO PESQUISEI QUE TALVEZ SOLUCIONARIA O ERRO*
* if (Convert.ToString(prop.Value) != v**)*
* v** = prop.Value.ToString();*
else
break;
* //vetor** = Convert.ToString(prop.Value.ToString()); *
switch (prop.Name)
{
case "e4_CODIGO":
if (prop.Value.ToString().Equals(selecionado))
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" selected=\"selected\" >");
else
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" >");
break;
case "e4_DESCRI":
sb.Append(Convert.ToString(prop.Value.ToString()) + "</option>");
break;
default:
break;
}
i++;
}
}
* sb.Append("</select>"); *
* } *
* } *
* context.Response.Write(sb.ToString());*
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Discussão (2)
Carregando comentários...