c# - Why is the "IndexOutOfRangeException" occuring -
i following this tutorial on how allow program open files using "open with" method found in windows. however, program loads, crashes error "indexoutofrangeexception".
my code follows.
public static void main(string[] args) { if(args[0] != null) { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new basic_word_processor()); basic_word_processor.instance.richtextboxprintctrl1.loadfile(@args.tostring()); } else { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new basic_word_processor()); }
what causing exception occur?
this: args[0]
because when args
null trying access first element of array not exists.
so fix program have check if args
not null:
if(args != null && args.length > 0) { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new basic_word_processor()); basic_word_processor.instance.richtextboxprintctrl1.loadfile(args[0].tostring()); } else { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new basic_word_processor()); }
Comments
Post a Comment