java - newInstance() | ClassNotFoundException | NoClassDefFounfError -




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?

enter image description here

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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -