Script Error in Event Log: "Object reference not set to an instance of an object"

Posts: 72
Working on a script that will automatically hide one label and show another when another widget has a dynamic background. Getting the "Object reference not set to an instance of an object" error in the event log and I have no idea why.

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;

namespace Scripts
{
public class ShowDriverScript : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Get the label running this converter script
// This label is showing the dynamic image
var label = item as Label;

var path = label.DynamicBackground.GetAbsolutePath(item.Theme);

var widget = item.Theme.Widgets.Find("W_DriverInfoLarge");
var subw = widget.SubWidgets.Find("SW_DriverInfoFollowL_Base");
var normlabel = subw.Labels.Find("L_DriverInfoFollowL_Number");
var newlabel = subw.Labels.Find("L_DriverInfoFollowL_Number_Driver");

if (System.IO.File.Exists(path))
{
normlabel.AnimateHide("0");
newlabel.AnimateShow("0");
return "";
}

else
{
normlabel.AnimateShow("0");
newlabel.AnimateHide("0");
return "";
}
}
}
}
Posts: 785
The first thing to try is check if label is null:
var label = item as Label;
if (label == null)
return "";


If that doesn't fix it, check similarly all the other widgets, labels, etc that you use. Final thing may be 'path' that is null but I doubt it.
Posts: 72
I had that in there originally and wasn't getting an error but it was hiding the dynamic background of the widget I had the script on and I have no idea why. This script is definitely not that important, I can just add a condition flag for showing drivers - I was just trying to get stuff to stick on the wall.