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 6794891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:16:36+00:00 2026-05-26T18:16:36+00:00

I have a class SomeTaskManager with an abstract method runATask . I want to

  • 0

I have a class SomeTaskManager with an abstract method runATask.
I want to execute the runATask method via reflection,
this is my code : what am I missing?

SomeTaskManager pm= (SomeTaskManager)context.getSomeTaskManager(); 
Class c = Class.forName( pm.getClass().getName() ); 

Method[] allMethods = c.getDeclaredMethods();

for (Method m : allMethods) {
    if (!m.getName().equals("runATask")) {
        continue;
    }
    m.invoke( c ,new Object[] { someParam, null, 1});
    break;
}  

I’m getting this errors

java.lang.IllegalArgumentException: object is not an instance of the class
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at de.vogella.android.downloadmanager.DownloadManagerActivity.riflesso(DownloadManagerActivity.java:250)
at de.vogella.android.downloadmanager.DownloadManagerActivity.onCreate(DownloadManagerActivity.java:68)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  • 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-05-26T18:16:37+00:00Added an answer on May 26, 2026 at 6:16 pm
    java.lang.IllegalArgumentException: object is not an instance of the class
        at java.lang.reflect.Method.invoke(Method.java:507)
    

    Aha, here

    m.invoke(c, new Object[] { someParam, null, 1});
    

    you’re passing the Class instead of an instance of it. You need to pass pm (the concrete instance) to it instead:

    m.invoke(pm, new Object[] { someParam, null, 1});
    

    This problem would likely be spotted sooner by just reading the code if you used full and self-documenting variable names instead of nothing-saying abbreviations. I’d suggest to work on that as well.


    Unrelated to the concrete problem, the following line

    Class c = Class.forName( pm.getClass().getName() ); 
    

    can be simplified as follows

    Class c = pm.getClass();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class in server side and I want use method of this class
I have class method: public object MyMethod(object obj) { // I want to add
I have class method that returns a list of employees that I can iterate
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I have class A: public B { ...} vector<A*> v; I want to do
I have class X and in it there is a static method called doStuff()
I have class MyContainer < ActiveRecord::Base :has_many MyObjects, :dependent => :destroy end I want
I have class dot and have html code like that: <span class=dot>Text1</span> <span class=dot>Text2</span>
i have class, with fields of double? type. with reflection i get fields Parameters
i have class like this DrillDownAppAppDelegate.h PictureCell.h RootViewController.h SlideShowViewController.h DrillDownAppAppDelegate.m PictureCell.m RootViewController.m SlideShowViewController.m i

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.