java - NoSuchMethodException for public no argument constructor in Inner Class -


i defined public no-argument constructor inside inner class, , code keeps throwing nosuchmethoexception when call getconstructor().

i'm calling problem method within outer class using:

addlisteners( info_boxes, infoboxlistener.class.getname() ); 

my inner class:

public class infoboxlistener implements view.onclicklistener {     public infoboxlistener()     {         //why isn't constructor being found?     }      @override     public void onclick(view view)      {         //some code              } } 

the method throwing exception:

private void addlisteners( list<view> views, string class_name ) {            try          {             class<?> clazz = class.forname( class_name );              constructor<?> ctor = clazz.getconstructor(); //exception              ( view view : views )             {                 object object = ctor.newinstance();                 view.setonclicklistener( (view.onclicklistener) object );             }          }          catch (classnotfoundexception e)          {             log.i("mine",  "class not found: " + e.getmessage() );         }         catch (nosuchmethodexception e)          {             log.i("mine",  "method not found: " + e.getmessage() );         }         catch (exception e)          {         } } 

my google-fu has failed me. in world doing wrong?

in java, can't call constructor of inner class without passing outer class parameter, this:

class<?> outerclass = class.forname("myouterclassname"); object outerinstance = outerclass.newinstance();  class<?> innerclass = class.forname("myinnerclassname"); constructor<?> ctor = innerclass.getdeclaredconstructor(outerclass);  object innerinstance = ctor.newinstance(outerinstance); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -