0

Im using aspx engine. I've been trying to push data into my list but i don't know how. every time i run the program it says create new instance of an object..im not too sure what they talking about..but i did create an instance of the class but still didnt work Can anyone please help me

this is my trying to populate data in my homecontroller

    public ActionResult GetEvent()
    {
        try
        {

            string i = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
            string et = "KI2XfwQNByLPFdK4i3a74slLT7sjjzYRi9RR7zEtCoQ%3D";
            string t = "20111128183020";
            string _checkingUrl =  String.Format("http://172.22.22.10/SampleAPI/Event/GetEvents?at={0}&et={1}&t={2}&responseFormat=json", i, et, t);
            System.Net.HttpWebRequest request=System.Net.WebRequest.Create(_checkingUrl) as System.Net.HttpWebRequest;
            System.Net.HttpWebResponse response=request.GetResponse() as System.Net.HttpWebResponse;
            System.IO.StreamReader _readResponse=new System.IO.StreamReader(response.GetResponseStream());
            //The encrypted dynamics response in either xml or json
            var _responseAsString=_readResponse.ReadToEnd();
            JavaScriptSerializer parseResponse = new JavaScriptSerializer();

            List<Event> events = parseResponse.Deserialize<List<Event>>(_responseAsString);

            Event eventOjb = new Event();
            events.Add(eventOjb);

            ViewBag.eventss = events;

            _readResponse.Close();
            // check json object
            return Content(_responseAsString.ToString());  



        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            //log error
        }
        return View();
    }

this is my Event class that is in the model folder

  using System;
  using System.Collections.Generic;
 using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


 namespace StopMalaria.Models
 {
public class Event
{
    public string event_key { get; set; }
    public string user_token { get; set; }
    public string event_set_key { get; set; }
    public string event_type { get; set; }
    public string event_date { get; set; }
    public string event_amount { get; set; }
    public string event_location_key { get; set; }
    public string event_location_name { get; set; }
    public string event_location_city { get; set; }
    public string event_location_state { get; set; }
    public string event_location_country { get; set; }
    public string event_acknowledged { get; set; }
}

}

this is my html trying to step through the list and create a table and error message comes on the foreach loop that says Object reference not set to an instance of an object

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    GetEvent
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


   <table id="eventist" border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>
                event_key
            </th>
             <th>
                user_token
            </th>                
            <th>
                event_set_key
            </th>           
            <th>
                event_type
            </th>
             <th>
              event_date
            </th>
              <th>
                event_amount
            </th>
             <th>
                event_location_key
            </th>                
            <th>
                event_location_name
            </th>           
            <th>
                event_location_city
            </th>
             <th>
              event_location_state
            </th>
            <th>
                event_location_country
            </th>
             <th>
              event_acknowledged
            </th>
        </tr>
    </thead>
    <tbody>
    <%List<StopMalaria.Models.Event> events = new List<StopMalaria.Models.Event>();%>
    <%events = ViewBag.eventss;%>

    <% foreach (var item in events )
       { %>

        <tr>
            <td>
                <%: item.event_key%>
            </td>
            <td>
                  <%: item.user_token%>
            </td>               
            <td>
                <%: item.event_set_key%>
            </td>           
            <td>
                <%: item.event_type%>
            </td> 
             <td>
                <%: item.event_date%>
            </td>
            <td>
                  <%: item.event_amount%>
            </td>               
            <td>
                <%: item.event_location_key%>
            </td>           
            <td>
                <%: item.event_location_name%>
            </td> 
             <td>
                <%: item.event_location_city%>
            </td>
            <td>
                  <%: item.event_location_state%>
            </td>               
            <td>
                <%: item.event_location_country%>
            </td>           
            <td>
                <%: item.event_acknowledged%>
            </td>                   
        </tr>

    <% } %>
    </tbody>
    </table>






</asp:Content>

An alternative option would be using the PHP ImageMagick extension, Imagick.

You can create the rectangle by setting the background parameter of the Imagick::newImage function, the cicle using the ImagickDraw::circle function, and the key is to apply the circle using the Imagick::compositeImage and only copying the transparency over. This will prevent you from having a solid image with a transparent circle on top; everything that is transparent in the mask will be transparent on the original image.

The below code should do the trick (although I am sure it will need a few tweaks to meet your needs :P):

<?php

    $base = new Imagick("before.png");
    $base->cropImage(512, 512, 0, 0);
    $base->setImageMatte(true);

    $mask = new Imagick();
    $mask->newImage(512, 512, new ImagickPixel("transparent"));

    $circle = new ImagickDraw();
    $circle->setFillColor("black");
    $circle->circle(150, 150, 100, 100);

    $mask->drawImage($circle);

    $base->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0);

    $base->writeImage('after.png');
    header("Content-Type: image/png");
    echo $base;

?>
4

1 回答 1

0

究竟是在哪里抛出异常?

从什么返回

 _readResponse.ReadToEnd();

在您尝试反序列化您的响应后,events会是什么样子?

最后,您确定这不会导致问题:

        Event eventOjb = new Event();
        events.Add(eventOjb);

不会设置任何字符串属性,这将导致空指针异常。

于 2012-06-18T20:49:02.120 回答