I defined a public no-argument constructor inside an inner class, and my code keeps throwing a NoSuchMethoException
when I call getConstructor()
.
I'm calling the problem method within the outer class using:
addListeners( info_boxes, InfoBoxListener.class.getName() );
My inner class:
public class InfoBoxListener implements View.OnClickListener
{
public InfoBoxListener()
{
//Why isn't this constructor being found?
}
@Override
public void onClick(View view)
{
//some code
}
}
The method throwing the exception:
private void addListeners( List<View> views, String class_name )
{
try
{
Class<?> clazz = Class.forName( class_name );
Constructor<?> ctor = clazz.getConstructor(); //EXCEPTION
for ( 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. What in the world am I doing wrong?