While developing a button, I want the output file generated by the button to have a predefined name consisting in a constant string "PositionalAccuracySamplePoints" and a variable string consisting on the first 15 characters of my gdb Name.
I am new to coding and struggling with understanding what I am doing wrong when trying to call the gdbName variable. I acutally believe that it has to do with the _gdbName value that I define outside the method, that is not getting the substring value that is given inside the method.
private static String _inputGdbPath = ("C:\\Users\\GMartin\\Documents\\Entorno pruebas\\Datos_SEA\\SEA19_0308_07C_20190513.gdb");
public static String _gdbName;
public Salida(String gdbName)
{
GeodatabaseManage gdbManageInput = new GeodatabaseManage(_inputGdbPath);
gdbName = _inputGdbPath;
_gdbName = gdbName.Substring(gdbName.LastIndexOf('\\') + 15);
}
public string fcName = String.Format("PositionalAccuracySamplePoints" + " _ " + "{0}", _gdbName);
With this code I get a NullValueReference exception, as mentioned has to do with the _gdbName of the last line not getting the value of de _gdbName of the inside but the empty value of the String.
Thanks in advance
It seems that there are some problems with your code. Here is what I can see based on what you share.
_inputGdbPathis never assigned.gdbNamethat you are replacing with the_inputGdbPath, which, as said on item 1, is never assigned.GeodatabaseManagebased on the_inputGdbPath, which is never used and could return some null reference, as the_inputGdbPathis null._gdbName = gdbName.Substring(15). ThegdbNameis the parameter received and that now is being replaced by the (null)_inputGdbPath. If you just need this parameter, you can remove the rest of the code on the constructor and leave only this line._inputGdbPathandgdbName.private setand assign the value directly inside the constructor. This way, the app will not do the concatenation of the string every time you try to get it. And you for sure can improve the format of the string.