Questions tagged [getconstructor]

17 questions
16
votes
5 answers

getConstructor with no parameters

I can't seem to use getConstructor for constructors with no parameters. I keep getting the following exception: java.lang.NoSuchMethodException: classname.() Here is the code: interface InfoInterface { String getClassName(); String…
user3086720
  • 191
  • 1
  • 1
  • 7
9
votes
3 answers

Java Reflection getConstructor method

Lets say I have classes A and B, where B extends A. I also have a constructor in B with one argument which is of type A. I also have an object of type B called bObj. Is there a way to call B.class.getConstructor(new Class[] { bObj.getClass() }) and…
user1305056
4
votes
2 answers

Java - getConstructor()?

I wrote the question as a comment in the code, I think its easier to understand this way. public class Xpto{ protected AbstractClass x; public void foo(){ // AbstractClass y = new ????? Car or Person ????? /* here I need a…
rasgo
  • 1,381
  • 4
  • 15
  • 28
3
votes
3 answers

Class.getConstructor function parameters

I'm studying this piece of code and got stucked in the commented row: protected T creaOggetto(Class classe, int id) { try { Package pacchetto = classe.getPackage(); String nomePacchetto = pacchetto.getName(); …
Gerico0889
  • 57
  • 1
  • 6
3
votes
1 answer

How to create an instance if a inner class with getConstructor()

Possible Duplicate: Java: How to load a class (and its inner classes) that is already on the class path? Could someone help me understand how to create an instance of an inner class using getConstructor. Here is where I am at right now. …
2
votes
1 answer

Alternatives to Class.getConstructor [for performance reasons]

I am trying to dynamically load ~10,000 classes and have code which looks like: Class c = getClass().getClassLoader().loadClass(className); Constructor constr = c.getConstructor(String.class); constr.newInstance(myString); On profiling, I…
2
votes
1 answer

getConstructor() returning NoSuchMethodException when called by a Class type variable

I keep getting the following exception when using getConstructor() on a type Class variable: java.lang.NoSuchMethodException: Main$Person.() The getConstructors() and getDeclaredConstructors() methods are working fine. I'm expecting the code to…
Jaguar Nation
  • 122
  • 11
2
votes
2 answers

Error executing CustomAttributeBuilder with type XmlDocument

I have the following code as part of a system for generating interfaces using reflection.emit class Class1:Attribute { public Class1(XmlDocument doc) { } } var type = typeof(Class1); var ctore = type.GetConstructor(new[] {…
user3815881
  • 83
  • 1
  • 4
1
vote
1 answer

GetConstructor.invoke error

This is a study project. I have three database classes A,B,C. There is a factory class that receives thru its constructor which class's object to create. Each of the three classes[A,B,C] has a constructor with a parameter to supply the database…
user20358
  • 14,182
  • 36
  • 114
  • 186
1
vote
1 answer

I don't know how to use class types as parameter

So I am creating a spigot plugin but that's not so important. I have a Selection class that keeps information about a 2D area with the x,z,width,depth stuff. At a certain point a rectangle or an ellipse will be stuffed into that selection. My…
1
vote
1 answer

Java reflect getConstructor NoSuchMethodException error

I have one class called ICwsTransactionProcessing_Capture_CWSInvalidOperationFaultFault_FaultMessage as defined below public class ICwsTransactionProcessing_Capture_CWSInvalidOperationFaultFault_FaultMessage extends java.lang.Exception { …
Praveen Yadav
  • 391
  • 4
  • 13
0
votes
2 answers

GetConstructor returning nothing

I have two different GetConstructors(), one is returning what it should be returning the other however is returning nothing. ItemName is BSRPTReportPerformanceSubcontractorRating The first one which is returning what it properly should is: Shared…
mattgcon
  • 4,768
  • 19
  • 69
  • 117
0
votes
1 answer

How to instantiate an inner class with reflection?

I would like to get the Constructor of a nested class so that I can instantiate it. I want this to be an inner class so that I can access variables from its outer class. The code below throws a NoSuchMethodException with the inner prefix…
Crocodile
  • 5,724
  • 11
  • 41
  • 67
0
votes
1 answer

Get internal constructor in UWP

How to get internal parametrized constructor in UWP. Why there is no such overload in UWP? var ctr = typeof(T).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, CallingConventions.HasThis, …
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
0
votes
2 answers

Getting Enum class from generic type?

Suppose I have several classes: Class ExceptionA{ public ExceptionA(ExceptionA.ErrorCode errorCode){} setters... getters... public static enum ErrorCode{ EC_ABC,EC_XYZ,EC_123 } Class ExceptionB{ public…
Toni T
  • 1
1
2