Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
695
Error: Attempt to insert nil object from objects[0] with grid
posted

I am getting the following error:

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
  at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend_IntPtr_int (intptr,intptr,intptr,int)
  at MonoTouch.Foundation.NSArray.FromObjects (IntPtr array, Int32 count) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSArray.g.cs:108
  at MonoTouch.Foundation.NSArray.FromNSObjects (IList`1 items) [0x0004f] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSArray.cs:83
  at MonoTouch.Foundation.NSArray.FromNSObjects (MonoTouch.Foundation.NSObject[] items) [0x00002] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSArray.cs:49
  at Infragistics.IGGridViewDataSourceHelper.set_Data (MonoTouch.Foundation.NSObject[] value) [0x00000] in <filename unknown>:0
  at Advantage.IOS.Connectiongrid.connectionsViewController.ViewDidLoad () [0x00108] in /Users/pauldavey/GitHub/Advantage.IOS.Connectgrid/connectionsgridLib/connectionsViewController.cs:106
  at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_bool (intptr,intptr,intptr,bool)
  at MonoTouch.UIKit.UINavigationController.PushViewController (MonoTouch.UIKit.UIViewController viewController, Boolean animated) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UINavigationController.g.cs:178
  at Advantage.IOS.App.VIDashboard.homeViewController.<ViewDidLoad>m__2 (System.Object , System.EventArgs ) [0x00011] in /Users/pauldavey/GitHub/Advantage.IOS.App.VIDashboard/Advantage.IOS.App.VIDashboard/homeViewController.cs:84
  at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at Advantage.IOS.App.VIDashboard.Application.Main (System.String[] args) [0x00000] in /Users/pauldavey/GitHub/Advantage.IOS.App.VIDashboard/Advantage.IOS.App.VIDashboard/Main.cs:16

Now the code that I am using is as follows:

public partial class connectionsViewController : UIViewController
            {

                public IGGridViewDataSourceHelper configdsh = new IGGridViewDataSourceHelper ();
                public string _Title {get;set;}
                //public IGGridView configGrid = new IGGridView(new RectangleF(0,0,1024,705),IGGridViewStyle.IGGridViewStyleDefault);

                public connectionsViewController () : base ("connectionsViewController", null)
                {
                //    this.TabBarItem = new UITabBarItem("connections",UIImage.FromBundle("Tables and Charts Icon-01"),100);
                }

public override void ViewDidLoad ()
                {
                    base.ViewDidLoad ();

                    // Create a new gridview
                    var configGrid = new IGGridView(new RectangleF(0,0,1024,705),IGGridViewStyle.IGGridViewStyleDefault);

                    // Enable flexible width so that the grid feels its parents view
                    configGrid.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

                    // Configure grid theme
                    configGrid = configuretheme.themegrid(configGrid);
                    
                    // Disable swipe to delete, since we are using a context style menu on the device delete
                    configGrid = gridconfig.enablerowdeletion (configGrid,false);

                    // Enable column resizing for the user - single tap a column header to show adjorner, then tap anyother column to remove it.
                    configGrid.ColumnResizing = IGGridViewColumnResizeAction.IGGridViewColumnResizeActionAdorner;
                    
                    // Add gridview to the current view
                    this.View.Add(configGrid);
                    
                    // Sort out custom column headers
                    var customcolumnheaders = new Dictionary<string, string>
                    {
                            {"ID", "id"},
                            {"Server", "server"},
                            {"Port", "port"},
                            {"Username", "username"}

                        // Don't bother throwing in a password custom header since we dont want to see it in the grid!
                       
                    };

                    configdsh = customheaders.configureheadertitles (configdsh,customcolumnheaders);

                    // Ignore the password field!
                    configdsh.FieldsToIgnore.Add (new NSString("password"));

                    // TESTING**
                        common.loadconnectionsfile ();
                        var test = common.configgriddata.ToArray ();
                    //    configdsh.InvalidateData (false);
                    configdsh.Data = test;        //common.configgriddata.ToArray ();

                    if (configdsh.Data == null) {
                        configGrid.DataSource = configdsh;
                    }

                    configGrid.ReloadData();
}

}

Parents
  • 695
    posted

    Apologies I posted without all the info :(

    The common.loadconnectionsfile ();  call loads the contents of a file which has been serialized to Json.

    public class common
        {
            public static configDataObject griddataObject = new configDataObject();            
            public static List<NSObject> configgriddata = new List<NSObject>();


            public static void loadconnectionsfile(){

                string pathTofile = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
                string filePath = Path.Combine(pathTofile, "vmware_connections.json");

                if (File.Exists(filePath)) {
                    StreamReader sReader = new StreamReader (filePath);

                    common.configgriddata.Clear ();
                    while (sReader.Peek() != -1)
                    {
                        try {
                            string line = sReader.ReadLine();
                            if (line.Length > 0){
                                //JsonSerializerSettings settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All}; 
                                JsonSerializerSettings settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.All}; 
                                var lineDeserialized = JsonConvert.DeserializeObject<configDataObject>(line,settings);

                                common.configgriddata.Add (lineDeserialized);
                            }
                        } catch (Exception ex) {
                            Console.WriteLine ("ERROR:  " + ex.Message);
                        }
                    }
                }
            }

            public static void writeconnectionsfile(){

                string pathTofile = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
                string filePath = Path.Combine(pathTofile, "vmware_connections.json");

                StreamWriter sWriter = new StreamWriter (filePath,false);
                foreach (configDataObject connElem in common.configgriddata) {
                    JsonSerializerSettings settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.All}; 

                    string lineToWrite = JsonConvert.SerializeObject (connElem,Formatting.None,settings);
                    sWriter.WriteLine (lineToWrite);
                }
                sWriter.Close ();
            
            }


        }

        [Serializable()]
        public class configDataObject : NSObject
        {
            [Export("ID")]
            public string ID {get; set;}
            
            [Export("Server")]
            public String Server {get; set;}
            
            [Export("Port")]
            public String Port {get; set;}
            
            [Export("Username")]
            public String Username {get; set;}
            
            [Export("Password")]
            public String Password { get; set; }
            
            public configDataObject(){}
        }
    }

    When I run the project it blows up with the error I posted about on the configdsh.Data = test; line. The object that I am passing in looks ok though ? (see attached screenshot).

    Any ideas?

Reply Children