Hi Experts,
If I am clicking the Cancel button without selecting any file in the below screenshot, i am facing null exceptions. and getting below error.
"The menu item with name couldnot be opened.
Object reference not set to an instance of an object"
The below code I am using for this.
try
{
//Upload a file
fileUpload = File::GetFileFromUser(classStr(CSVFileUploadTemporaryStorageStrategy));
file = CommaTextStreamIo::constructForRead(fileUpload.openResult()); — Here my debugger throws null exception
if (file)
{
if (file.status())
{
throw error("@SYS52680");
}
file.inFieldDelimiter(','); //separator
file.inRecordDelimiter('\r\n');
}
How can I get rid of this error?
Thanks,
Mark
This exception is thrown when you’re trying to call a method on a reference that points to null instead of an object. In your case, either fileUpload
variable contains null, or the exception is actually thrown inside of openResult() or constructForRead(). Use the debugger to identify the exact place.
You can’t fix it without finding it first.
Hi @MartinDrab,
Thanks for your reply. Please find the below Screenshot. As suggested I debugged and found the below area.
Could you please guide me on this.
Thanks,
Mark
Unfortunately, your screenshot doesn’t show any new information. Check if fileUpload is null or not. If not, it means that the exception is called by the call of fileUpload.openResult(), but inside one of the methods called at the line. Open exception details and look at the stack trace to see where it happened.
Hi @MartinDrab ,
I have checked that. FileUpload is ‘null’ after debugger passing that line.
Thanks,
Mark
All right, so you know why you’re getting this exception. The next step is finding out why GetFileFromUser()
returns null.
First of all, try calling F&O with &mi=SysClassRunner&cls=SysFlushAOD.
Then I suggest your share code of your CSVFileUploadTemporaryStorageStrategy
class with us (maybe we’ll spot a bug there) and you debug GetFileFromUser()
method. Make sure you have debugging enabled for the model containing File
class.