Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:25:26+00:00 2026-06-05T19:25:26+00:00

public class Test1<Type> { public Type getCompositeMessage(Type… strings) { Type val = (Type) ;

  • 0
public class Test1<Type>
{
    public Type getCompositeMessage(Type... strings)
    {
        Type val = (Type) "";

        for (Type str : strings) {
            val = (Type) ((String)val + (String)str);
        }
        return val;
    }
}

Retrieving method:

try
{
    Class<?> c = Class.forName("test1.Test1");
    Method[] allMethods = c.getDeclaredMethods();
    for (Method m : allMethods) {
        String mname = m.getName();
        System.out.println(mname);
    }

    Method m = c.getMethod("getCompositeMessage");
    m.setAccessible(true);
    Object o = m.invoke(c, "777777777777777777777777");
    System.out.println(m);
}
catch (Exception e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Output:

getCompositeMessage
java.lang.NoSuchMethodException: test1.Test1.getCompositeMessage()
at java.lang.Class.getMethod(Unknown Source)
at test1.Main.main(Main.java:25)

But name of method is exactly the same! Why I receive NoSuchMethodException ?
thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:25:28+00:00Added an answer on June 5, 2026 at 7:25 pm

    After you fixed the misspelling, you are still looking for the wrong method:

    The method is defined as:

    getCompositeMessage(Type... strings)
    

    but you are looking for

    getCompositeMessage()
    

    without parameters.

    You need to use:

    c.getMethod("getCompositeMessage", Object[].class);
    

    The next problem will be the call to invoke(), you are passing the class references in stead of the object on which the method should be called.

    The next bug is that you are not passing the correct arguments to the function:

     Object o = m.invoke(new Test1<String>(), new Object[] {
              new String[] {"777777777777777777777777"}});
    

    And the next problem is that you want output the result of the method instead of the method-object in the following line:

    System.out.println(o);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote two methods to check there performance public class Test1 { private String
I have following code public class TEST { public static void main(String arg[]){ try
public interface ITest { void Somethink(); } public class Test1 : ITest { public
public class Test{ public void Test(String name){}; public static void main() { Test t=new
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char
I have the following class: public class Test { public string Text { get;
I've the following classes KeyValue.java package test; public class KeyValue<T> { private String key;
Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string>
Suppose I have the following classes: public class Test { public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.