Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Exception type: NullReferenceException

$
0
0

I have the following scenario: an web part that retrieve an Item from a list

code:

namespace SPPMyWebPart.VWPMyWebPart { [ToolboxItemAttribute(false)] public partial class VWPMyWebPart : WebPart { SPList list = web.Lists["MyList"]; protected void Page_Load(object sender, EventArgs e) { int i = Convert.ToInt32(request.QueryString["item"]); getItem(i); } public void getItem(int i) { SPListItem item = list.GetItemById(id); txtTitle.Text = item["Title"]; } } }

the first time everything happens well

but in a second time i get  this error:

Exception type: NullReferenceException 

message: Object reference not set to an instance of an object ...

in the reference of the "list"

anyone know why this is happening?



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>