java - newInstance() | ClassNotFoundException | NoClassDefFounfError -
this question has answer here:
following code, when giving command java test getting error noclassdeffounderror , when give command java test s error classnotfound.
as per knowledge if newinstance() used , class not found classnotfound error should com
why there difference in errors?
class test { public static void main(string[] args) throws exception { system.out.println("in main method"); object o = class.forname(args[0]).newinstance(); system.out.println(o.getclass().getname()); } } class student { } class teacher { }
as per knowledge if newinstance() used , class not found classnotfound error should com
@callersensitive public static class<?> forname(string classname) throws classnotfoundexception { class<?> caller = reflection.getcallerclass(); return forname0(classname, true, classloader.getclassloader(caller), caller); }
forname
method throwing classnotfoundexception
exception.
newinstance
method throwing instantiationexception
, illegalaccessexception
i'm not able reproduce issue, in each case classnotfoundexception
wiki
Comments
Post a Comment